about 1 change of laravel 5.3,
now, have model want save.
before, doing :
$result = $model->save();
and know if operation successful.
now, new:
the eloquent save method returns false if model has not been changed since last time retrieved or saved.
mentioned in upgrade guide
if model has not changed, return false.
now code tell me there error, because trust true or false result of or bad operation.
so now, how can check save() successful, if didn't change data???
check if model dirty.
// b $result = !$model->isdirty() || $model->save()
- if model modified,
a
false
,b
shouldtrue
.$result
true
- if model not modified,
a
true
,$result
true. - if model modified , didn't saved sucessfull,
false
both ina
,b
,$result
false.
i explain: happens because eloquent db query if changed. laravel developers decided change save()
response, can know if query made, or if changed.
according @patricus comment, first solution not trigger saving()
, updating
events, obvious reason: php many languages stop evaluating or expression when true
found.
so if need events being triggered, should this:
$wasclean = $model->isclean(); // oposite of 'isdirty()' $result = $model->save() || $wasclean;
Comments
Post a Comment