php - 无法在 laravel 8 中显示图像
问题描述
我在 Laravel 8 应用程序中有一个搜索功能,可以从数据库中返回数据以及图像。除图像外,其他所有内容均显示。有两个图像列,我需要将这些图像与其他列的数据一起输出。我已经完成了从存储到公共的符号链接,但仍然无法显示图像,但其他列返回数据。我会很感激一些帮助。
图像存储在 storage/public 文件夹中。
存储控制器
public function store(Request $request)
{
$image1 = uniqid() . $request->file('image1')->getClientOriginalName();
$post = new Post;
$post->name = request('name');
$post->product_image1 = $image1;
$request->file('image1')->storeAs('public', $image1);
$post->save();
return redirect(route('users.index'));
}
搜索控制器
public function search(Request $request, User $user){
$term = $request->input('search');
$matchedTerms = Post::where('name', 'LIKE', '%' . $term . '%')->get();
return view('profiles.search-results', compact('matchedTerms', 'user_id'));
}
刀
@forelse($matchedTerms as $matchedTerm)
<p>{{$matchedTerm->name}}</p> //this displays okay
<img src="/storage/public/{{$matchedTerm->product_image1}}" /> //this does not display
@empty
<p>no match found</p>
@endforelse
解决方案
推荐阅读
- sql - 如何根据数据库版本运行不同的 SQL
- ios - Cordova iOS 应用程序在 WKWebView 更改后显示带有随机文本的白屏
- python-3.x - 如何在 imaplib.IMAP4_SSL.search() 上设置多个条件(AND 和 OR)
- mysql - 使用 MySQL 8.0 命令行创建表时出现错误 1064 (42000)
- c++ - 如何从 tif 图像中拆分多个页面/图层并使用 C++ OpenCV 将其保存为单独的图像?
- r - 转换为一个测量单位
- python - Ceph Octopus zabbix config-show 失败并出现 python 错误
- sql - 页面、联系人和公司的 INNER JOIN - 重复条目
- css - 即使使用 display:inline-block 也不会水平收缩
- javascript - Magento 2 - 如何使用 php 或 js 更改产品的数量(在产品页面上)?