首页 > 解决方案 > 无法在 Laravel 中检索上传的图像文件的 URL

问题描述

我上传的文件 (abc.png) 保存在文件夹中:

storage\app\public\uploaded_files\abc.png

当我使用$url = Storage::disk('public')->url($business->logo);它时,它会生成http://127.0.0.1:8000//storage/abc.png一个打开与路由相关的 URL。

filesystem.php我有以下条目。

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

路线

Route::get( '/{business_slug}/{item_name}-{encoded_id}', 
    'ItemController@single' )->name( 'single_item' );

我应该怎么做才能修复图像 URL 并使其公开可用?

标签: phplaravellaravel-5.5

解决方案


I see that your problem has been solved, but I'll leave another solution:

If you store your file in your public folder (or a subfolder in the public folder), you can easily access the file by using

{{ asset('images/' . $image) }}

The $image is just the filename, with it`s extension, and is being linked the to the subfolder 'images' in the public folder. This will work on any sub-page.


推荐阅读