我无法访问对象数组内部的图像访问数组。
*
在以下代码段中也失败:
$this->validate($request, [
'blocks.*' => 'array|required',
'blocks.*.position' => 'required|integer',
'blocks.*.block_title' => 'required|max:100',
'blocks.*.block_text' => 'required|max:500',
'block.*.images' => 'required',
'block.*.images.*' => '|mimes:jpeg,jpg,png,gif,svg|max:10240',
]);
我还尝试了以下方法:
$blocks = $request->blocks;
foreach ($blocks as $block) {
$images = $request->file('blocks.images');
我想创建包含图像的块。
答案 0 :(得分:0)
在请求中,您应该使用'blocks.*.images'
和'blocks.*.images.*'
而不是'block.*.images'
和'block.*.images.*'
。
要获取图像,您可以尝试:
$data = $request->all();
$blocks = $data['blocks'];
foreach ($blocks as $block) {
foreach ($block['images'] as $image) {
// $image should be a file
$file_name = $image->getClientOriginalName();
$file = Storage::putFileAs(
'path-to-save-file-at', $image, $file_name
);
}
}