Check if altered value changed key

Ever wanted to know if the changes you've made to a model have altered the value for a key? No problem, simply reach for originalIsEquivalent.

1$user = User::first(); // ['name' => "John']
2 
3$user->name = 'John';
4 
5$user->originalIsEquivalent('name'); // true
6 
7$user->name = 'David'; // Set directly
8$user->fill(['name' => 'David']); // Or set via fill
9 
10$user->originalIsEquivalent('name'); // false

Tip given by @mattkingshott

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord