LARAVEL 7 - config:clear 后图像未显示

LARAVEL 7 - Image not showing after config:clear

我正在研究 Laravel 7(在 Windows 10 上使用 Laragon 4.0),我从远程 url 下载和保存了一些文件。一切正常,但我不得不执行“php artisan config:clear”来更新 mysql 配置,之后保存在 storage/public 文件夹中的图像不再提供。

文件在那里但没有提供,然后我删除了 /storage/public 文件夹中的所有内容,删除了 /public 文件夹中到 /storage 的符号链接(自然执行“php artisan storage:link") 并像我之前那样用文件夹和文件再次填充 /storage/public 。文件夹结构在那里,文件也在那里,但是当我尝试访问它们时,出现 404 错误。

我尝试了“php artisan optimize:clear”和我在 Whosebug 上找到的每条建议,但似乎没有任何帮助,我不知道去哪里找,请帮助我。

这是我用于 download/save 图片的代码:

        $url = $team["logo"];
        $contents = file_get_contents($url);
        $name = substr($url, strrpos($url, '/') + 1);
        $file = 'public/team/logo/'. $name;

        Storage::put('team/logo/'. $name, $contents);

这是我在视图中显示图像的方式:

<img src="{{Storage::url($team->logo)}}" style="max-width:50px">

这是我在 filesystems.php

上的 public 磁盘配置
        'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

因为你的驱动设置为

'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

您的 Storage::disk('local') 绝对设置为 /storage/app/public。因此 $file = 'public/team/logo/'. $name; 变成 $file = 'team/logo/'. $name;

如果您正在使用 Intervention/Image 库,您可以考虑更改

$contents = file_get_contents($url);

$contents = File::make($url);

http://image.intervention.io/api/make