There is a table basket_items, which has a polymorphic relationship with other models. How can I make it so that if there is another connection in the Model, then that it would also be derived when requested.
This is where the second items has event_id and city_id, how can I get their models?
I was able to get the relationship for this item
$basket = Basket::with('items.entity')->with(['items' => function ($query) { $query->where('entity_type', '=', 'related_event')->with('entity.event'); }])->findOrFail($id); But so only one items are displayed.
If so
$basket = Basket::with('items.entity')->with(['items' => function ($query) { $query->where('entity_type', '=', 'related_event')->with('entity.event'); }])->with(['items' => function ($query) { $query->where('entity_type','<>', 'related_event')->with('entity'); }])->findOrFail($id); That, that first items will be gone.
If i do like this
$basket = Basket::with('items.entity')->with('entity.event')->findOrFail($id) That error occurs on other models, because there is no event dependency.
How can this be correctly implemented, a polymorphic link is used in basket_items. Maybe you can somehow check if there is such an attitude, if there is no such attitude, then simply not to deduce it?
UPD
On the screenshot, the output is like this:
$basket = Basket::with('items.entity')->findOrFail($id); 