如何从Laravel上的数组图像获取getClientOriginalName()?

时间:2019-12-09 16:56:09

标签: laravel

我有一个像这样的请求数组。...我有order_details表,我想更新列类别,注释和图片数据,这些数据中有我从请求中获得的orderid和skuid,...

array:7 [▼
  "orderid" => "191121120129KUR"
  "_token" => "1ov7aCP8JzzokWNfMpwntTH0Dv084HqwIqMUfLd1"
  "orderdet" => array:5 [▼
    0 => array:4 [▼
      "skuid" => "10006"
      "category" => array:2 [▼
        0 => "1"
        1 => "2"
      ]
      "remark" => "remarks 1"
      "foto" => array:2 [▼ 
        0 => Illuminate\Http\UploadedFile {#348 ▶}
        1 => Illuminate\Http\UploadedFile {#349 ▶}
      ]
    ]
    1 => array:4 [▼
      "skuid" => "10007"
      "category" => array:1 [▼
        0 => "1"
      ]
      "remark" => "remarks 2"
      "foto" => array:4 [▼
        0 => Illuminate\Http\UploadedFile {#350 ▶}
        1 => Illuminate\Http\UploadedFile {#351 ▶}
        2 => Illuminate\Http\UploadedFile {#352 ▶}
        3 => Illuminate\Http\UploadedFile {#353 ▶}
      ]
    ]
    2 => array:2 [▼
      "skuid" => "10008"
      "remark" => null
    ]
    3 => array:2 [▼
      "skuid" => "10138"
      "remark" => null
    ]
    4 => array:2 [▼
      "skuid" => "10078"
      "remark" => null
    ]
  ]
  "actioncomplaint" => "1"
  "salahsiapa" => "3"
  "remarkcust" => null
  "remarkfresh" => "Dani"
]

我想使用getClientOriginalName()存储图像名称,... 如何获取图像名称,这是我的控制器

foreach($request->orderdet as  $row)
        {
            $data = OrderDetail::where('data_order_id', $request->orderid)->where('skuid', $row['skuid'])->first();
            if(isset($row['category'])) {

                $data->remarkscomplaint = $row['remark'];
                $data->categorycomplaint = implode(',',  $row['category']);
                $data->fotocomplaint = $row['foto'];
                $data->save();
            }
        }

1 个答案:

答案 0 :(得分:0)

尝试类似的东西:

$fotos = $request->only(['foto']);
$fotoNames = []
foreach($fotos as $foto) {
 $fotoNames[] = $foto->getClientOriginalName();
}

$implodedFotos = implode(',' $fotoNames);

然后

  foreach($request->orderdet as  $row) {
        $data = OrderDetail::where('data_order_id', $request->orderid)->where('skuid', $row['skuid'])->first();

        if(isset($row['category'])) {

          dd($row['foto']); //Array of Image

          $data->remarkscomplaint = $row['remark'];
          $data->categorycomplaint = implode(',',  $row['category']);
          $data->fotocomplaint = $implodedFotos; // <- set your attribute with the variable we create with the names
          $data->save();
        }
  }

我想你也可以做类似的事情

$fotos = collect($request->orderset['foto'])
    ->map(function ($foto) {
    return $foto->getClientOriginalName();
    })
    ->implode(',');

$fotos->all(); // access the result

然后为了保存图像,this将为您提供帮助。

$foto->storeAs('path', 'filename');