无法访问 Laravel 存储目录

Cannot Access Laravel Storage Directory

我正在使用 Laravel 5.7。在我的本地主机上,我的存储工作正常,所有图像也显示,但在我的主机上,新图像不显示。

我在 blade.php 文件中使用以下代码:

{{ asset("storage/$slider") }}

在我的本地主机上它显示图像:

localhost:8000/storage/sliders/HKeGwcvnXbjuiA6g9wsjnoqphJc5DGup78D92b4F.jpeg

我无法访问我的网站:

http://mywebsite.com/storage/sliders/HKeGwcvnXbjuiA6g9wsjnoqphJc5DGup78D92b4F.jpeg

现在我使用这条路线并且成功了:

Route::get('storage/sliders/{filename}', function ($filename)
{

    $path = storage_path('app/public/sliders/' . $filename);

    if (!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
});

如果您有其他子目录,您可以使用:

Route::get('storage/{path}/{filename}', function ($path,$filename)
{

    $path = storage_path('app/public/'.$path.'/' . $filename);

    if (!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;
});