Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Track model changes after persisting to database #20129

Merged
merged 2 commits into from
Jul 18, 2017
Merged

[5.5] Track model changes after persisting to database #20129

merged 2 commits into from
Jul 18, 2017

Conversation

themsaid
Copy link
Member

Currently:

$user->name = 'new name';

// This returns the name attribute with its new value
$user->getDirty();

$user->save();

// Now that the user is saved getDirty() will return an empty array
$user->getDirty();

What Changed:

$user->name = 'new name';

$user->save();

// getChanges() will return an array of the name attribute with its new value
$user->getChanges();

This allows for doing some useful checks after model is saved, for example if a Server was activated we want to send notification to customer.

$server->update(request()->all());

if($server->isChanged('active') && $server->active){
   Notification::send(....);
}

@taylorotwell taylorotwell merged commit 709de09 into laravel:master Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants