如何使用图像数组使其成为内爆函数?我得到一个错误:
implode():传递的参数无效
我的控制器:
public function store(Request $request)
{
$this->validate($request, [
'promotion_image' => 'required'
]);
if ($request->has('promotion_image'))
{
//Handle File Upload
$promotion = [];
foreach ($request->file('promotion_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/promotion_images',$fileNameToStore);
array_push($promotion, $fileNameToStore);
}
$fileNameToStore = serialize($promotion);
}
else
{
$fileNameToStore='noimage.jpg';
}
foreach ($promotion as $key => $value) {
$promotionImage = new Promotion;
$promotionImage->promotion_image = implode(' , ',$value);
$promotionImage->save();
}
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
我的观点:
@foreach($promotions as $promotion)
<tr>
//HERE IS WHERE THE IMAGE ARE VIEWED <th><img src="{{ asset('storage/promotion_images/' . $promotion->promotion_image) }}" style="width:50px;height:50px;"></th>
<th><a href="/admin/airlineplus/promotions/{{ $promotion->id }}/edit" class="fa fa-edit btn btn-primary btn-lg"></a></th>
</tr>
@endforeach
1条答案
按热度按时间t0ybt7op1#
如果我没弄错的话,试着不用foreach循环
补充的:
如果视图中有该值并希望显示这些图像,则应执行以下操作: