gpt4 book ai didi

php - Laravel Livewire 文件上传返回 Null

转载 作者:行者123 更新时间:2023-12-05 04:28:03 27 4
gpt4 key购买 nike

我在使用 livewire 上传文件时遇到问题。我正在使用一个非常基本的示例来实现我的目标,但问题是它在提交时返回 null。

这是我的 Livewire Controller 代码:

class UploadPhoto extends Component

{

use WithFileUploads;



public $photo;



public function save()

{

dd($this->photo); //returns null

$this->validate([

'photo' => 'image|max:1024', // 1MB Max

]);



$this->photo->store('photos');

}

}





<form wire:submit.prevent="save">

<input type="file" wire:model="photo">



@error('photo') <span class="error">{{ $message }}</span> @enderror



<button type="submit">Save Photo</button>

</form>

最佳答案

你确定使用 withFileUploads 吗?

使用 Livewire\WithFileUploads;

关于php - Laravel Livewire 文件上传返回 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72685456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com