【发布时间】:2020-12-17 19:35:58
【问题描述】:
我正在尝试保存图像地址,但出现以下错误:Array to string conversion 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
]);
编辑:数组
我收到错误:数组到字符串的转换。你能帮帮我吗?
【问题讨论】:
-
已删除原始评论...
$this->imagenes是Array,这可能就是您的错误的来源。你的错误没有提到行号吗?我对 Livewire 不熟悉,所以我不得不问,你想用Property::create()做什么?它期待String,而不是Array -
如果在:$this->imagenes 用数组添加图片
-
是的,需要一个字符串,但我需要保存一个数组。
-
它不会让你保存数组 :) 你可以使用
json_encode($this->imagenes)将你的Array转换为String但我不知道这是否可行,因为我不知道知道Property::create做了什么。如果需要,您可以使用json_decode将String转换回Array。这有帮助吗? -
嗨,使用 json_encode 它为我保存了一条记录并错误地保存了地址。 "imagenesPropiedades\/T9wElIPuG0eDol6Q8fIvPxWPVH8I7bw7zEY8UGQG.jpeg" 也许你知道我如何首先在变量中创建数组?
标签: laravel image file-upload laravel-livewire