Answer the question
In order to leave comments, you need to log in
How to load all relations in Laravel 5.1 polymorphic relation?
There is a main Pattern model that has many Layer models .
There is a Layer model that has a polymorphic relation to the Image and Text models . The Text
model has no child relationship, while the Image has a one-to-one relationship with the File model .
In what way, when unloading the Pattern model , pull up all the Layers , each with its own additional relations?
Pattern::whereId($id)->with('layers.layereable')->get();
Answer the question
In order to leave comments, you need to log in
use Illuminate\Database\Eloquent\Relations\MorphTo;
$activities = ActivityFeed::query()
->with(['parentable' => function (MorphTo $morphTo) {
$morphTo->morphWith([
Event::class => ['calendar'],
Photo::class => ['tags'],
Post::class => ['author'],
]);
}])->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question