I am trying to fing how we can integrate Livewire
with spatie/laravel-medialibrary
in Laravel
. In this code I can get the image information when user submit the form, but I can't save an uploaded image with spatie/laravel-medialibrary
:
class ProfileComponent extends Component
{
use WithFileUploads;
public $photo;
//...
public function submit()
{
$this->validate($this->rules);
$user = User::find(auth()->user()->id);
$user->name = $this->name;
$user->family = $this->family;
$success = $user->save();
//...
try {
$user
->addMedia($this->photo)
->toMediaCollection(User::MEDIA_COLLECTION_NAME);
} catch (FileDoesNotExist | FileIsTooBig $e) {
dd($this->photo);
}
}
or I try to use this code, but I get an error too
->addMediaFromDisk('/livewire-tmp/'.$this->photo->getFilename())
here we don't have request
and by default livewire
used store
function for uploading images. how can we integrate them?