我正在尝试寻找我们如何Livewire
与spatie/laravel-medialibrary
in集成Laravel
。在这段代码中,我可以在用户提交表单时获取图像信息,但我无法保存上传的图像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);
}
}
或者我尝试使用此代码,但我也收到错误
->addMediaFromDisk('/livewire-tmp/'.$this->photo->getFilename())
这里我们没有request
默认livewire
使用store
的上传图片的功能。我们如何整合它们?