首页 > 解决方案 > 如何在刀片上显示保存在存储文件夹中的图像

问题描述

我想在刀片视图中显示保存在存储目录中的图像。我成功地将文件存储到 storage/app/public 文件夹,就像 ProfilesController 文件一样:

`if(request('image')) {
            $imagePath = request('image')->store('profile', 'public');

            $image = Image::make(public_path("storage/{$imagePath}"))->fit(1000, 1000);
            $image->save();
        }

        auth()->user()->profile->update(array_merge(
            $data,
            ['image' => $imagePath] 
        ));`

现在我想在我的 index.blade.php 文件中检索图像。这是如何做到的:

<img src="/storage/{{$user->profile->image}}" alt="">

laravel 文档说在我的终端中使用存储链接我这样做了

php artisan storage:link

我尝试了所有这些,但是视图中没有图像加载!

我在做什么错以及如何解决!

标签: phphtmllaravelstoragelaravel-blade

解决方案


您应该在用户配置文件模型中使用访问器,即:-

public function getImageAttribute($image) { return asset('storage'.$image); }


推荐阅读