Is there a simple way for the Eloquent save method to check if a row has actually changed? Something like affected_rows
for Eloquent?
The only workaround that I found was from Laravel Eloquent update just if changes have been made to do:
$user = Auth::user();
$timestamp = $user->updated_at;
$user->title = $request->input('title');
....
$user->save();
if($timestamp == $user->updated_at){
// row was not updated.
}
But is this possible to find this out shorter, without the need of a $timestep
variable and the check? I don't want to repeat that logic in every controller.
I am looking for something like this:
$user = Auth::user();
$user->title = $request->input('title');
....
if($user->save()){
// row was updated.
}
But this does not work since $user->save
returns true
in both cases. Is there another way?