Should I use Model Relationships vs Query Scopes and a simple mysql join?

Posted 9 months ago by inmn

Perhaps I am missing something; but when using .. belongsTo('App\Org') or $members = return $this->hasMany('App\Member'); models, I am finding that I often just return more than I need.


If an Org has Members; $org->with('members'); gives me


  • Members

If i want user data I have to do


Which gives me


  • Members
    • User Record

If the user has any related fields, like contact numbers I am then working with


  • Members
    • User Record
      • Related Models of User Record
        • Maybe even more

When returning public json output, i then have to clean up many of the fields being returned

(still learning how only return PARTS of the related models)

So with a query scope / custom mysql i could easily return a flat array of selected data for the memberDataOf($org)

What would you recommend?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.