I have a many-to-many polymorphic relationship defined like this:
public function images(): MorphToMany
{
return $this->morphToMany(
related: Image::class,
name: 'imageable',
table: 'imageables',
foreignPivotKey: 'imageable_id',
relatedPivotKey: 'image_id',
);
}
I want to also define a one-to-many relationship like morphOne()
that can do things like latestOfMany()
, oldestOfMany()
, and ofMany()
. The problem I’m having is that morphOne()
doesn’t allow me to pass in the name of the pivot table (imageables
in this example).
How do I create a relationship that accomplishes this?