所以,我试图显示图像,这里是我如何创建我的数据
public function create_supplier(Supplier $request)
{
$validatedData = $request->validated();
$extension = $request->file('logoimg')->getClientOriginalExtension();
$filename = $request->supplier_name . '.' . $extension;
$request->file('logoimg')->storeAs('/storage/supplier_logo/', $filename);
$supplier = ModelsSupplier::create([
'supplier_name' => $request->supplier_name,
'address' => $request->address,
'email' => $request->email,
'phone_number' => $request->phone_number,
'logoimg' => $request->logoimg
]);
return response()->json(['message' => 'Supplier successfully added', 'supplier' => $supplier]);
}
现在,我想在blade.php中显示徽标img
<tbody>
@foreach($suppliers as $supplier)
<tr>
<td>{{$supplier->id}}</td>
<td><img src="{{ asset('storage/supplier_logo/' . $supplier->logoimg) }}" alt="test"></td>
<td>{{$supplier->supplier_name}}</td>
<td>{{$supplier->address}}</td>
<td>{{$supplier->email}}</td>
<td>{{$supplier->phone_number}}</td>
</tr>
@endforeach
</tbody>
它已成功显示供应商名称、地址等。但是它显示的alt文本是“test”。该文件也已成功添加到我的storage/supplier_logo中。
然而,这是我的phpmyadmin中的值,C:\xampp\tmp\php15CC.tmp
请帮帮忙,谢谢!
1条答案
按热度按时间r8xiu3jd1#
你需要保存图片的url,保存到你的数据库中,而不是$request->logoimg .
storeAs()返回文件路径
我不测试代码,也许你需要一些调试