Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
May 8, 2024
Monitoring changes made to model instances is a typical requirement in Laravel applications. Finding out if a model has changed after it was pulled from the database is made easy with Laravel. This blog post will explain how to check if a model in Laravel has been modified.
The wasChanged method from Laravel allows you to determine whether any model attributes have changed. If an attribute has changed since the model was last saved during the current request cycle, this function returns true; if not, it returns false.
Here’s how you can use the wasChanged method:
Above returns true as we changed the author name.
Method also allows us to check by specific field or array of fields passing as below.
While passing with array if any of the fields were changed then it also returned true.
As seen in above code it returns false as it doesn’t change.
Laravel also provides a couple of more methods like isDirty() and isClean() to identify the status of the model.