如何在刀片上显示保存在存储文件夹中的图像

问题描述

我想在刀片视图中显示保存在存储目录中的图像。我成功地将文件存储到 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

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

我做错了什么以及如何解决

解决方法

    <img class="" src="{{ Storage::disk('name-option')->url('full path.jpg') }}"  alt="">

disk('name-option') 是你可以跳过的选项

<img class="" src="{{ Storage::url('full path.jpg') }}"  alt="">
,

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

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