5 Relationship Tips - Laravel

morcosgad

Morcos Gad

Posted on December 3, 2022

5 Relationship Tips - Laravel

My dear, I found this wonderful source https://www.youtube.com/watch?v=ijt10uTM8LY that shows us 5 Laravel Relationship Tips that are useful to us. They will make us happy in our projects and write our code. I will touch quickly on them, but visit the source and deepen it a lot

  • withDefault()

We have in the database some Category that do not have a parent, and we do not want to show the empty value. Here comes the withDefault()

Image description

Image description

Image description

  • Eager and Lazy Loading With Constraint

Image description

  • Querying Relationship Existence With Constraint

Let's single out some limitations on finding results using whereHas

Image description

  • Shorter Syntax to Query Relationship Existence

Image description

  • Eager Loading and Query Relationship Existence Combo

Image description

I hope you enjoyed the code and I wish you always a happy code .

💖 💪 🙅 🚩
morcosgad
Morcos Gad

Posted on December 3, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related