In this series, I show you new features and improvements to the Laravel framework since the original release of version 8. This week is about the Database and Eloquent features in Laravel 8. The team added so many great improvements to the weekly versions that I split the Database and Eloquent features into two blog posts.
The explain() method allows you to receive the explanation from the builder (both Query and Eloquent).
You may add additional constraints to each of these queries using the MorphTo relation's constrain method: use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\MorphTo; $comments = Comment::with(['commentable' => function (MorphTo $morphTo) { $morphTo->constrain([ Post::class => function (Builder $query) { $query->whereNull('hidden_at'); }, Video::class => function (Builder $query) { $query->where('type', 'educational'); }, ]); }])->get(); v8.17.2 Added BelongsToMany::orderByPivot() (https://github.com/laravel/framework/pull/35455)