FilamentF
Filament3y ago
Sven

MorphMany Relations not (yet) supported in V3 relationshipManager?

Hey!

TL/DR


The docs state These are compatible with HasMany, HasManyThrough, BelongsToMany, MorphMany and MorphToMany relationships. on https://filamentphp.com/docs/3.x/panels/resources/relation-managers#relation-managers---interactive-tables-underneath-your-resource-forms but when creating a RelationManager for a morphed relation, I receive App\Models\Product::logs(): Return value must be of type Illuminate\Database\Eloquent\Relations\HasMany, Illuminate\Database\Eloquent\Relations\MorphMany returned

Detailed example


I have a Model Product, which has its own ProductRessource and a model History. In my History I have:

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


and in my Product I have

    public function logs(): HasMany
    {
        return $this->morphMany(History::class, 'logable');
    }


In my LogRelationManager I added

class LogRelationManager extends RelationManager
{

    protected static string $relationship = 'logs';


But when opening my ProductResource, I receive

App\Models\Product::logs(): Return value must be of type Illuminate\Database\Eloquent\Relations\HasMany, Illuminate\Database\Eloquent\Relations\MorphMany returned
Solution
Oops. I'm stupid. It was my own typehint :x
Was this page helpful?