Answers for "laravel observer get old value"

PHP
1

laravel read origanl value before update

$model->getOriginal('attribute')
Posted by: Guest on December-27-2020
0

laravel observer get old value

User::updating(function($user)
{
    if ($user->username != $user->getOriginal('username')) {
        doSomething();
    }

    // If you need multiple attributes you may use:
    // $originalAttributes = $user->getOriginal();
    // $originalUsername = $originalAttributes['username']; 
});
Posted by: Guest on June-09-2021

Browse Popular Code Answers by Language