Laravel Pro Tips
#eloquent #relationships
Here's a pro tip π₯ for all you Laravel developers: You can customize the default order of data retrieved from relationships! #Laravel #PHP #PHPRC
Mohammad Haris β‘
π₯ #Laravel Tip: Eloquent offers many undocumented methods that can help to make your code easier to read. For example, the whereBelongsTo method simplifies finding resources that belong to a model instance.
Matt Kingshott
#eloquent #relationships #eager loading
π₯ #Laravel Tip: Eager loading model relationships is way more efficient, however if used blindly, it can result in the fetching of data that you donβt actually need. To help avoid this problem, consider adding a constraint to the queryβ¦
#Laravel tip: Find Related IDs on a BelongsToMany Relationship with using allRelatedIds() method π
Shahghasi Adil
Laravel Tip π‘ v9.16 introduces a new withWhereHas() to reduce code duplication π Time to do a bit of cleaning π§Ή
Philo Hermans
When eager loading relationships in Laravel, you can specify the columns you need directly in the `with` method π
Daniel Eckermann
An efficient way of checking if a relation exists in Laravel is to use withExists. It performs a simple existence check and returns a boolean. By default it would return a "posts_exists" value on the User. You may alias it like in the example below to make it more readable.
#eloquent #models #relationships
πΆοΈ #Laravel Tip: The Eloquent push() method allows you to save the Model and all of its relations in one shot. Compared to the save() that only saves the Model itself. Here's a practical example to illustrate π₯ https://t.co/N6q2wyDrya #PHP #Laravel
Bilal Haidar - Available 4 Laravel gigs
#relationships #foreign key
#Laravel #Database Tip: While creating migrations you may also specify the desired action for the "on delete" and "on update" properties of the constraint. Here are more methods that #Laravel provides π #Laravel #Database #PHP https://t.co/pr3arpPGdk
Laravel Eloquent
May 2nd, 2022
The new findOr method in Laravel 9.x
A minor release for Laravel 9.x dropped a few days ago and among lots of new features and improvements, this release has introduced a new method called findOr in the Eloquent Builder and Relations.