【发布时间】:2021-05-17 22:32:39
【问题描述】:
我正在尝试显示存储文件夹中的一些存储图像,但它没有显示! 这是控制器:
public function store(Request $request)
{
$templates = new templates([
"image_path"=>$request->image->hashName(),
"image_path2"=>$request->image2->hashName(),
"image_path3"=>$request->image3->hashName(),
]);
$request->image->store('public');
$request->image2->store('public');
$request->image3->store('public');
$templates->save();
这里是源图片:
@foreach($products as $templates)
<td> <img src= "storage/app/public/uploads/{{$templates->image_path}}"></img></td>
<td><img src= "storage/app/public/uploads/{{$templates->image_path2}}"></img></td>
<td><img src="storage/app/public/uploads/{{$templates->image_path3}}"></img></td>
路线如下:
route::get('/view','App\http\controllers\TemplatesController@index');
这里是索引函数:
public function index()
{
$products = templates::all();
return view('products.marja', compact('products'));
}
【问题讨论】:
-
您发布的控制器代码处理存储图像,但您说无法显示它们。你能展示一下试图获取它们的操作吗?
-
不确定,但可能与
$templates末尾多余的逗号有关,不需要? -
据我在您发布的附加信息中看到的,您发送到视图中的变量称为
$products,但您尝试使用$templates。您是否收到“未定义变量”通知? -
@Crimin4L 结尾的逗号是可选的,但不会导致任何问题,它是数组的有效语法。
-
请分享更多细节。 究竟是什么不起作用?您尝试过什么来解决问题?
标签: php mysql laravel image src