ebess / advanced-nova-media-library

A Laravel Nova field for displaying, creating, updating and ordering a Spatie Media Library model.
592 stars 296 forks source link

Argument #1 ($model) must be of type Spatie\MediaLibrary\HasMedia, App\Models\ #270

Open mateusgalasso opened 3 years ago

mateusgalasso commented 3 years ago

Help

I'm getting this error, when I'm loading the resource detail page

Spatie\MediaLibrary\MediaCollections\MediaRepository::getCollection(): Argument #1 ($model) must be of type Spatie\MediaLibrary\HasMedia, App\Models\CoordenadorPedagogico given, called in /var/www/html/vendor/spatie/laravel-medialibrary/src/InteractsWithMedia.php on line 290

I'm using use InteractsWithMedia; trait

Help

ClausMunch commented 3 years ago

You need to make it without a return type (You just miss the :void after the function name).

`public function registerMediaCollections(): void { $this->addMediaCollection('my-collection') //add options ...

// you can define as many collections as needed
$this->addMediaCollection('my-other-collection')
    //add options
    ...

}`

Spatie documentation

glennforrest commented 2 years ago

Hey @stonkeep I just ran into this issue myself, the reason it wasn't working for me is that I'd forgotten the implements HasMedia interface on my model.

edrisaturay commented 11 months ago

worse. it's just there in the documentation.