【问题标题】:Problem with uploading file with livewire component使用 livewire 组件上传文件的问题
【发布时间】:2021-09-28 07:32:15
【问题描述】:

我创建了一个组件来创建帖子,我的表单有一个带有 wire:model="post.post_image" 的输入文件,当我选择图像时,我创建了一个函数来打印图像数据,但它仍然给我 null .

use WithFileUploads;
public $post;

protected $rules = [
    'post.post_image' => 'sometimes|image|max:5000',
    ];

public function mount ()
{
    $this->post = new Post;
}
public function uploadPostImage(Request $request)
{
    dd($request->file('post.post_image'));
}
public function render ()
{
    return view('livewire.post.create');
}

html code :

<div class="sm:col-span-6"> <input type="file" accept="image/*" wire:model="post.post_image" name="post.post_image" wire:change="uploadPostImage"> </div>

当我上传图片时它给我 null 并且在控制台给我这个错误

error

【问题讨论】:

    标签: php laravel laravel-blade


    【解决方案1】:

    正如您在文件上传的实现模型中看到的here,在使用 Livewire 时依靠请求是没有用的。 查看文档中的实现模型,很简单。

    【讨论】:

    • 我检查了很多次文档,但它仍然给我错误!
    • 您在此处发布的实现与有关如何上传文件的文档无关。请再次检查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    • 2021-02-03
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多