【发布时间】:2021-06-22 21:27:25
【问题描述】:
在全新的 Laravel 8 安装中,我遵循以下步骤:
-
php artisan storage:link
-
在
/public/storage/中创建文件夹images/并在其中粘贴一个名为picture.png的图像 -
在 web.php 中我定义了这样的路由:
Route::get('/picture', function( return response()->file(Storage::url("images/picture.png")); ))
但是,如果我在浏览器中访问该路由,则图片不显示并抛出以下错误:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
The file "/storage/images/picture.png" does not exist
只有当response()->file()中的url以./为前缀表示当前目录时才有效,如下所示:
return response()->file('./'.Storage::url("images/picture.png"));
我认为在本地使用相对路径不是一个好主意,存储和文件方法应该处理这个问题。也许这甚至是框架的问题。
任何想法如何绕过这个黑客?
【问题讨论】: