The `is()` method of one-to-one relationships for comparing models

We can now make comparisons between related models without further database access.

1// BEFORE: the foreign key is taken from the Post model
2$post->author_id === $user->id;
3 
4// BEFORE: An additional request is made to get the User model from the Author relationship
5$post->author->is($user);
6 
7// AFTER
8$post->author()->is($user);

Tip given by @PascalBaljet

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