Let's get started quickly In some cases, clean code must be used as in the following
// Don't do this
Post::where('category_id', $category->id)
->where('author_id', $user->id)
->first();
// Do this
Post::whereBelongsTo($category)
->whereBelongsTo($user, 'author')
->first();
// Don't do this
$post->author_id == $user->id;
// Do this
$post->author()->is($user);
I hope you enjoyed the code.
Top comments (0)