What is the standard and professional way to query Laravel polymorphic relations?

25 Views Asked by At

Trying to fetch persons table based on the result of the polymorphic relations. What is the professional standard way on doing this? Thank you very much!

Insertable model

public function insertables() {
return $this->morphMany(Insertable::class, 'insertable');
}

Person model

public function insertable () {
return $this->morphTo();    
}

$people = Person::find($id)->insertables;
$peopleIds = $people->pluck('person_id');
return response()->json(Person::whereIn('id', $peopleIds)->get());
0

There are 0 best solutions below