1

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());
codevour
  • 11
  • 1
  • try this [eloquent](https://laravel.com/docs/8.x/eloquent-relationships#customizing-the-pivot-attribute-name) you can pass na argument within the with paramerter – Japs Apr 22 '21 at 07:58

0 Answers0