I set my Media Model in config file that is extend of Spatie\MediaLibrary\Models\Media and it is in App\Models namespace.
when I try to add registerMediaConversions method to my model that has some media, raise this error:
Declaration of App\Models\Task::registerMediaConversions(?App\Models\Media $media = NULL) must be compatible with Spatie\MediaLibrary\HasMedia\HasMedia::registerMediaConversions(?Spatie\MediaLibrary\Models\Media $media = NULL)
this error is completely clear. the method should completely compatible with method that declares in interface HasMedia.
This is worked for me. (php7.3, laravel6.4)
public function registerMediaConversions()
{
}
public function registerMediaConversions(Media $media = null)
{
}
In case someone else has this error... don't forget to add this at the beginning of your model:
use Spatie\MediaLibrary\MediaCollections\Models\Media;
public function registerMediaConversions(Media $media = null) : void
Just add the void part to the end of the function
worked for me @priceluke, thanks
otherwise I would get:
_Method 'App\Channel::registerMediaConversions()' is not compatible with method 'Spatie\MediaLibrary\HasMedia::registerMediaConversions()'._
But what if I use a custom Media model? I still get this error..
@cerw hi, do you find a solution at this problem please?
@valh1996 not really I had to use the Media that comes from the Package. So far no real problem but you do all the custom relationship method from the custom model.
Most helpful comment
public function registerMediaConversions(Media $media = null) : voidJust add the void part to the end of the function