Let's get started quickly I found new things in Laravel 9.16 Released I wanted to share with you.
- Eloquent withWhereHas() https://github.com/laravel/framework/pull/42597
method that simplifies cases where you have to repeat code used to both filter with whereHas and select the same record via with()
CollectionModel::whereHas('products', function ($query) {
$query->where('enabled', true)->where('sale', true);
})->with(['products' => function ($query) {
$query->where('enabled', true)->where('sale', true);
});
Using the withWhereHas method, you can simplify your code around this use case
CollectionModel::withWhereHas('products', fn ($query) => $query->where('enabled', true)->where('sale', true));
I hope you enjoyed with me and to learn more about this release visit the sources and search more. I adore you who search for everything new.
Source :- https://laravel-news.com/laravel-9-16-0
Source :- https://www.youtube.com/watch?v=ZEDUihpRQMM
Top comments (0)