Laravel Community Tools by Tighten

Sanjok Dangol

Joined: 5 years ago
Total tricks: 9
Last trick: 5 years ago

Submitted tricks

if you want to use ORM eloquent to get a query with the third table and select only particular attributes then here is the trick. Here users can have multiple positions in a company and each user has their own user profile. *note that user_id must be here to fetch data with a specific column. without foreign key eloquent cannot map relational table
sanjok1988 5 years ago 18441
Here posts and categories have many to many relationships. the tricks are to fetch posts having a particular category attribute with categories details.
sanjok1988 5 years ago 11607
wrong and right way to write eloquent
sanjok1988 5 years ago 8510
search query from scope in laravel model
sanjok1988 5 years ago 9800
The main difference is which side of the relationship holds the relationship's foreign key. The model that calls $this->belongsTo() is the owned model in one-to-one and many-to-one relationships and holds the key to the owning model.
sanjok1988 5 years ago 20240
Here a user has a location with many to many positions. This query finds users having position id 4 and location id 6. the tables are users, profile, locations. and profile has location_id.
sanjok1988 5 years ago 12821
case: user has many posts and post has many comments. we need user's posts with comments:
sanjok1988 5 years ago 13359
GroupBy clause with multiple columns select in laravel
sanjok1988 5 years ago 20518
This method list out all the registered middleware in laravel
sanjok1988 5 years ago 22311