Laravel 7 中找不到文件异常

File Not Found Exception in Laravel 7

我正在开发一个 laravel 应用程序,我想通过单击一个按钮来下载文件。我已将文件存储在 /storage/app/public/1.pdf 中,并在 public 文件夹中创建了一个符号 link。现在我尝试了很多方法来下载文件,但每次都收到错误 File Not Fount Exception at path.

我试过以下方式下载文件:

1 -
$name = "file.pdf";
$file = storage_path(). "/app/public/1.pdf";
$headers = array(
'Content-Type: application/pdf');
return Storage::download($file, $name, $headers);

2 - 
$name = "file.pdf";
    $file = public_path(). "/storage/1.pdf";
    $headers = array(
          'Content-Type: application/pdf',
        );

    return Storage::download($file, $name, $headers);


3 - 
$name = "file.pdf";
    $file = Storage::url("1.pdf");
    $headers = array(
          'Content-Type: application/pdf',
        );

    return Storage::download($file, $name, $headers);  

这是我收到的错误消息:

我尝试了很多次,但没有任何效果。提前感谢任何帮助。

来自文档:
The Local Driver

When using the local driver, all file operations are relative to the root directory defined in your filesystems configuration file. By default, this value is set to the storage/app directory.

因此,如果文件存储在 storage/app/public/1.pdf 中,请不要向 Storage facade 传递一个像这样的绝对路径:

$file = storage_path(). "/app/public/1.pdf";
return Storage::download($file);

而是使用相对于 filesystems 配置文件中定义的 root 目录的路径:

$file = "public/1.pdf";
$name = "file.pdf";
return Storage::download($file, $name);