Skip to content
Advertisement

What does isDirty() mean in Laravel?

First of all, I am not familiar with Laravel so much (or with the term “dirty” for that matter).
I stumbled upon this line of code –

if ($this->isDirty('status')) {
    if (Notification::has('website-status-' . strtolower($this->status))) {
        Notification::set($this->account, 'website-status-' . strtolower($this->status), $this->emailAttributes())
            ->email();
    }
}

And I couldn’t understand what that means exactly. I tried to find out on the internet but the Laravel site only says this

“Determine if a given attribute is dirty”

which doesn’t really help…

Advertisement

Answer

When you want to know if the model has been edited since it was queried from the database, or isn’t saved at all, then you use the ->isDirty() function.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement