What isDirty () means in Laravel?

First of all, I am not very familiar with Laravel (or the term "dirty")
. I came across 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 could not understand what this means. I tried to find out on the Internet, but the Laravel site only talks about it

"Determine if this attribute is dirty."

which doesn’t help much ...

+13
php laravel
source share
2 answers

If you want to know if the model has been changed because it was requested from the database or not saved at all, you use the function ->isDirty() .

+22
source share

In support of the accepted answer:

 $model = $Model::find(1); $model->first_column = $request->first_value; $model->second_column = $request->second_value; $model->third_column = $request->third_value; if($model->isDirty()){ // the model has been edited, else codes here will not be executed } $model->save(); 
0
source share

All Articles