Closed fsaravi closed 4 years ago
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.
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;
wow it worked for me like magic, but the issue I have now is that when I try posting the model, it display 'csrf token mismatched'
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;
wow it worked for me like magic, but the issue I have now is that when I try posting the model, it display 'csrf token mismatched'
Ok sorry I have seen the problem, it was because, the page session has expired, I refreshed the page and tried and it worked
Hi, sorry, I know this issue is closed, but I ran across this too, when using a custom model extending the MediaCollection model. I fixed it by using registerAllMediaConversions() instead of registerMediaConversions().
custom media model App\Models\Media
<?php
namespace App\Models;
use App\Http\Traits\Uuids;
use Spatie\MediaLibrary\MediaCollections\Models\Media as BaseMedia;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Media extends BaseMedia
{
use HasFactory, Uuids;
protected $attributes = [
'access' => 'restricted',
'status' => 'viewable',
'publicApproved' => false,
'publicReviewed' => false
];
}
User Model
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Http\Traits\Uuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Haruncpi\LaravelUserActivity\Traits\Loggable;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class User extends Authenticatable implements HasMedia
{
use HasApiTokens, HasFactory, Notifiable, Loggable, Uuids, InteractsWithMedia;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function registerAllMediaConversions(): void
{
$this->addMediaConversion('thumb')
->width(50)
->height(50)
->sharpen(10);
}
}
Hope this might help someone in the future if you get here by searching for this issue.
Just adding to this: make sure to restart your server after changes. The fixes weren't being picked up until I restarted my server
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:
this error is completely clear. the method should completely compatible with method that declares in interface HasMedia.