将多个图像保存到Laravel Livewire

问题描述

我正在尝试保存图像地址,但出现以下错误:数组到字符串的转换Laravel。

如何保存图像的路线?在官方文档中没有指出这一点。

我的代码如下:

查看

<input wire:model="imagenes" type="file" class="form-control-file" multiple>

组件

use WithFileUploads;
public $imagenes = [];


foreach ($this->imagenes as $pathgalería) {
       $pathgalería->store('imagenesPropiedades');
}

$properties = Property::create([

    'imagenes' => $this->imagenes

]);

编辑:阵列

enter image description here

我得到错误:数组到字符串的转换。你能帮我吗?

解决方法

我想我知道您在说什么。您是要保存上传文件的哈希名称吗?

要实现此目标,您应该使用此代码:

$properties = Property::create([
    'imagenes' => $this->imagenes->hashName()
]);

或者,有一个youtube视频系列,实际上涵盖了laravel livewire简单文件上传和多个文件上传功能。

简单文件上传>>> https://www.youtube.com/watch?v=epf6mChMYok

多个文件上传>>> https://www.youtube.com/watch?v=nwnp3L4Oy-Q