Php 在Laravel中的新模型上调用save()时,Phaza点保存优于其他属性
我正在控制器中使用Laravel 5.1和Php 在Laravel中的新模型上调用save()时,Phaza点保存优于其他属性,php,laravel-5,Php,Laravel 5,我正在控制器中使用Laravel 5.1和Phaza\LaravelPostgis\Geometrics\Point类。 当我以点对象作为属性保存新的Ride模型时,它有时会覆盖Laravel中模型中的其他属性。 如果检查数据库,数据将正确保留,但在控制器中进一步使用时,保存的模型具有不正确的属性 模型定义如下 <?php namespace App; use Illuminate\Database\Eloquent\Model; use Phaza\LaravelPostgis\Ge
Phaza\LaravelPostgis\Geometrics\Point
类。
当我以点对象作为属性保存新的Ride
模型时,它有时会覆盖Laravel中模型中的其他属性。
如果检查数据库,数据将正确保留,但在控制器中进一步使用时,保存的模型具有不正确的属性
模型定义如下
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Phaza\LaravelPostgis\Geometries\Point;
use Phaza\LaravelPostgis\Eloquent\PostgisTrait;
class Ride extends Model
{
use PostgisTrait;
/**
* Define which properties are postgis types
*
* @var array
*/
protected $postgisFields = ['start_location' => Point::class, 'end_location' => Point::class];
}
保存之前,模型对象如下所示
{
"ride": {
"start_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.780843
]
},
"end_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.980843
]
},
"vehicle_id": 6
}
}
保存后,模型对象如下所示
{
"ride": {
"start_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.780843
]
},
"end_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.980843
]
},
"vehicle_id": {
"type": "Point",
"coordinates": [
28.276439,
-25.980843
]
},
"updated_at": "2019-11-21 14:10:51",
"created_at": "2019-11-21 14:10:51",
"id": 4
}
}
我注意到,如果我将2个点的赋值移动到save()之前,我会得到正确的输出。有人能帮我理解为什么会发生这种情况吗?你能从这里展示你的全部储蓄代码吗到这里
$newRide->save()代码>。我现在已经遇到过好几次了,当我创建一个新模型时,它似乎发生了。然后我必须为它运行$model=$model->fresh()
,修复它的字段
{
"ride": {
"start_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.780843
]
},
"end_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.980843
]
},
"vehicle_id": {
"type": "Point",
"coordinates": [
28.276439,
-25.980843
]
},
"updated_at": "2019-11-21 14:10:51",
"created_at": "2019-11-21 14:10:51",
"id": 4
}
}