如何通过工厂将虚假坐标转化为点列?

huangapple go评论65阅读模式
英文:

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 . ")')"),

huangapple
  • 本文由 发表于 2023年6月5日 11:32:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定