0

我正在尝试寻找我们如何Livewirespatie/laravel-medialibraryin集成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的上传图片的功能。我们如何整合它们?

4

1 回答 1

0

使用此代码

$user->addMedia($this->photo->getRealPath())->toMediaCollection('Colle');
于 2021-02-09T19:38:24.457 回答