I am using Laravel 5.1 and the Phaza\LaravelPostgis\Geometries\Point
class in a controller. When I save a new Ride
model with the Point object as an attribute it sometimes overwrites other attributes in the model in Laravel. If you check the Database, the data is persisted correctly but the saved model has the incorrect attributes when being used further in the controller.
The model definition is as follows
<?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];
}
I create a new mode with $newRide = new Ride();
, assign the needed attributes to the object and save the model with $newRide->save();
The Model object looks like this before the save
{
"ride": {
"start_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.780843
]
},
"end_location": {
"type": "Point",
"coordinates": [
28.276439,
-25.980843
]
},
"vehicle_id": 6
}
}
The Model object looks like this after the save
{
"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
}
}
I noticed that if I change the order in witch I assign the attributes to the new model I do get the correct output. Can someone please help me understand why this is happening?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire