phpmyadmin 在foreach blade.php中显示图片

cotxawn7  于 2023-10-20  发布在  PHP
关注(0)|答案(1)|浏览(160)

所以,我试图显示图像,这里是我如何创建我的数据

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
请帮帮忙,谢谢!

r8xiu3jd

r8xiu3jd1#

你需要保存图片的url,保存到你的数据库中,而不是$request->logoimg .
storeAs()返回文件路径

$filepath = $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' => $filepath
]);

我不测试代码,也许你需要一些调试

相关问题