jeudi 27 octobre 2016

Laravel model "start" date attribute being changed

I have a controller which is updating a model through a request object. It looks

$save_series = Series::where('id','=',$request->input('data.item.id'))->with('booking')->first();
$save_series->name              = $request->input('data.item.name');
$save_series->color                 = str_replace('#', '', $request->input('data.item.color'));
$save_series->production_company    = $request->input('data.item.production_company');
$save_series->booking->start        = $request->input('data.item.booking.start');
$save_series->booking->end          = $request->input('data.item.booking.end');
$save_series->booking->save();
$save_series->save();               

When I save this the related "booking " object is updated. If the "end" date attribute is changed, then the "start" attribute's time is set to the current time; this shouldn't be the case! It seems to be ignoring the parsed $request start time completely.

On the related model to the booking I have put a setter mutator to see if the issue resides before that point - the date is being parsed correctly, yet once it hits the database it has changed. My setting (just for this test) looks like this:

public function setStartAttribute($time) {
    error_log(":::::::::::TEST BELOW:");
    error_log($time);
    return $time;
}

The error log result is:

PHP message: :::::::::::TEST BELOW:
PHP message: 2016-10-27 00:00:00" 

Yet the database field of "start" for this record reads:

2016-10-27 13:07:53

Please can someone explain what on earth is happening here; I'm completely and utterly lost!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire