Check for specific model was created or found

If you want to check for specific model was created or found, use wasRecentlyCreated model attribute.

1$user = User::create([
2 'name' => 'Oussama',
3]);
4 
5// return boolean
6return $user->wasRecentlyCreated;
7 
8// true for recently created
9// false for found (already on you db)

Tip given by @sky_0xs

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