Answer the question
In order to leave comments, you need to log in
Eloquent model where relation morphs?
Hello. There is a model, Item, used throughout the project. In order not to fence dozens of pivot tables, I decided to make it simpler:
class Item extends BaseModel
{
public function owner()
{
return $this->morphTo();
}
}
Item::whereRelation('owner', $user)->get()
$user->items
Answer the question
In order to leave comments, you need to log in
I realized that in other parts of the service you will also have to use $model->items(), so it's closed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question