Argument 1 passed to Spatie\MediaLibrary\MediaCollections\FileAdder #2070
Unanswered
mostafasamirs
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Argument 1 passed to Spatie\MediaLibrary\MediaCollections\FileAdder::processMediaItem() must be an instance of Spatie\MediaLibrary\HasMedia, instance of App\ModelOfficer\Accountant given, called in
medialibrary\src\MediaCollections\FileAdder.php on line 379
model
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
class Accountant extends Model
{
use InteractsWithMedia;
protected $filable = ['image'];
public $appends = ['image'];
protected $hidden = ['media'];
public function registerMediaConversions(Media $media = null): void
{
$this->addMediaConversion('thumb')
->width(100)
->height(100);
}
public function getImageAttribute()
{
if ($this->getFirstMedia('OfficerCategory\Accountant')) {
return $this->getFirstMedia('OfficerCategory\Accountant')->getFullUrl('thumb');
} else {
return '';
}
}
}
controller store
$Accountant->addMedia($request->image)->toMediaCollection('Accountant')->getPath();
Beta Was this translation helpful? Give feedback.
All reactions