英文:
How to make a fake coordinate to a point column through factory?
问题
我试图通过工厂创建一个包含 point
列的虚假数据。
迁移中的坐标列:
$table->point('coordinate');
我在工厂中尝试过以下方法:
'coordinate' => DB::raw("Point(" . fake()->latitude() . " " . fake()->longitude() . ")"),
'coordinate' => "Point(" . fake()->latitude() . " " . fake()->longitude() . ")",
'coordinate' => fake()->latitude() . " " . fake()->longitude(),
'coordinate' => [fake()->latitude(), fake()->longitude()],
是否有一种方法可以伪造带有 point
列的坐标或在工厂中使用原始 SQL?
英文:
I'm try to make a fake data through factory that contains a point
column.
The coordinate column in migration:
$table->point('coordinate');
I've tried in 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 any way to fake coordinate with point
column or using raw sql in factory?
答案1
得分: 2
我认为你可以尝试使用 ST_GeomFromText
函数:
'coordinate' => DB::raw("ST_GeomFromText('POINT(" . $this->faker->latitude . " " . $this->faker->longitude . ")')"),
英文:
I think you can try it with ST_GeomFromText
'coordinate' => DB::raw("ST_GeomFromText('POINT(" . $this->faker->latitude . " " . $this->faker->longitude . ")')"),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论