Laravel Community Tools by Tighten

Tag "relationships" tricks

27 tricks
Get results in a table when there are no results for the relationship
wallacemax... 10 years ago 20125
This is my personal reference.
Mahmoudz 10 years ago 15333
This sample covers the following scenario: Every course has may chapters, while a chapter can belong to only one course. In the other hand every chapter has many videos while a video can belong to many chapters. I will write the description below.
Mahmoudz 10 years ago 13364
Add the attributes on the second parameter of the attach function.
Mahmoudz 10 years ago 15011
in this example there is a one to many relation. [course has many chapters]
Mahmoudz 10 years ago 11294
A variation of http://www.laravel-tricks.com/tricks/column-selection-in-eager-loading Credits: http://stackoverflow.com/questions/16994253/laravel-eager-loading-load-only-specific-columns Warning: this trick does not work on many-to-many relations, see: https://github.com/laravel/framework/issues/2966
orlissenbe... 11 years ago 18788
Since Eloquent doesn't do a real join when using "with" this will add a simple join method without having to worry about the join columns since it's all stored with the models anyway. It will also select all the columns from the joined table with an added prefix of the table name.
phazei 11 years ago 45204
If we have a blog, sometimes we want to display all latest posts by category. Take an example with this website where I put those posts in a carousel on the homepage: http://dadack.com
mercuryser... 11 years ago 17542