search

Home  >  Q&A  >  body text

How to make fake coordinates of point column through factory?

I tried making fake data via a factory containing the point column.

Coordinate columns in migration:

$table->point('coordinate');

I tried it at the factory:

'coordinate' => DB::raw("Point(" . fake()->latitude() . " " . fake()->longitude() . ")"),

'coordinate' => "Point(" . fake()->latitude() . " " . fake()->longitude() . ")",

'coordinate' => fake()->latitude() . " " . fake()->longitude(),

'coordinate' => [fake()->latitude(), fake()->longitude()],

Is there a way to fake the coordinates with the point column or use raw sql in the factory?

P粉933003350P粉933003350324 days ago419

reply all(1)I'll reply

  • P粉042455250

    P粉0424552502024-02-04 14:25:16

    I think you can try using ST_GeomFromText

    'coordinate' => DB::raw("ST_GeomFromText('POINT(" . $this->faker->latitude . " " . $this->faker->longitude . ")')"),

    reply
    0
  • Cancelreply