如何从数据库中检索单个字段数组数据并将它们分开 - 使用 laravel、PHP

How to retrive single field array data from database and separate them- using laravel, PHP

我正在尝试为我的产品上传多张图片,并将这些图片的名称作为数组存储在数据库中。 我的代码是这样工作的-

$images = $request->file('images');      

if (isset($images)) {
  foreach($images as $image){
    $imagename = $slug.'-'.$currentDate.'-'.uniqid().'.'.$image->getClientOriginalExtension();
    if (!file_exists('uploads/product/images')) {
       mkdir('uploads/product/images', 0777, true);
    }
      $image->move('uploads/product/images', $imagename);
      $data[] = $imagename;
    }
            
  }else{
     $data[] = 'default.png';
  }

  $product = new Product();
  $product->images = json_encode($data);

并且存储在 images 字段中的数据如-

["jeans-2020-08-13-5f352f18b30a4.jpg","jeans-2020-08-13-5f352f18b36a0.jpg","jeans-2020-08-13-5f352f18b3a2c.jpg"]

**问题是我如何分隔此图像名称以在 Laravel Blade 中显示图像? **
建议我,如果有另一种方法可以在laravel-6

中上传多个图像或多个值

您需要反序列化图像名称,然后循环遍历它们:

@foreach(json_decode($product->images) ?? [] as $image)
    <img src="uploads/product/images/{{ $image }}">
@endforeach