我正在尝试找出如何在Laravel中集成Livewire和spatie/laravel-medialibrary。在这段代码中,我可以在用户提交表单时获取图像信息,但不能用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函数来上传图片。我们如何集成它们呢?
发布于 2021-02-10 03:38:24
使用此代码
$user->addMedia($this->photo->getRealPath())->toMediaCollection('Colle');https://stackoverflow.com/questions/66114049
复制相似问题