You could use Route::bind()
.
Route::bind('id', function($id) {
return Post::with('media', 'user')->findOrFail($id);
});
Or you could pre-populate the $with property of the model. In this case every time you fetch a Post it will eager-load those too.
class Post extends Eloquent
{
protected $with = ['media', 'user'];
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community