【发布时间】:2019-04-27 03:02:39
【问题描述】:
我想在一行中显示我的数据库中显示的所有图像。这些图像存储在我数据库中的一个数组中,因此它位于一行中。目前在我的代码中,图像未显示,并且不可用
这是我的控制器
存储数据
$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';
}
if (count($promotion)) {
$implodedPromotion = implode(' , ', $promotion);
$promotionImage = new Promotion;
$promotionImage->promotion_image = $implodedPromotion;
$promotionImage->save();
return redirect('/admin/airlineplus/promotions')->with('success', 'Image Inserted');
}
return redirect('/admin/airlineplus/promotions')->with('error', 'Something went wrong.');
这是我的视图
@foreach($promotions as $promotion)
<tr>
<th><img src="{{ asset('storage/promotion_images/' . $promotion->promotion_image) }}" style="width:50px;height:50px;"></th>
@endforeach
【问题讨论】:
-
检查您的控制台。它将显示无法加载的图像 URL。根据该 URL,您需要修改图像路径。你能告诉你控制台错误吗?
-
请查看新的编辑。我添加了问题..没有错误只是图像没有显示
-
@BanujanBalendrakumar 我编辑上面的问题请看图片..它没有错误,我的问题是图片没有显示
-
该错误仅显示在控制台中。你应该检查你的路径。右键单击图像并单击
Open Image in New Tab然后显示图像URL,并显示目录树。 -
@BanujanBalendrakumar 我这样做了,据说找不到页面
标签: php html mysql arrays laravel