下载链接存储文件不工作- Laravel


Download link for files in storage not working - Laravel

我正在把我的文件存储,它正在工作。但是,下载链接返回一个错误。

这是允许用户上传文件的视图

<div class="form-group{{ $errors->has('notes') ? ' has-error' : '' }}">
       <label class="col-md-4 control-label">Upload your notes</label>
           <div class="col-md-6">
               <input type="file" class="form-control" name="notes">
                   @if ($errors->has('notes'))
                       <span class="help-block">
                               <strong>{{ $errors->first('notes') }}</strong>
                       </span>
                    @endif
           </div>
</div>

这是我在控制器中处理请求的方法。

    Storage::put(
    'notes/' . $note->id . '.pdf',
     file_get_contents($request->file('notes')->getRealPath())
    );

一切如果着火和pdf文件都被存储在我的存储/应用/笔记目录。

我用来下载文件的链接是:/notes/90.pdf,其中'90'是笔记id。

我一直得到错误

RouteCollection.php第161行出现NotFoundHttpException:

你需要为你的文件定义一个路由。

Route::get('notes/{id}', function ($id) {
    return response()->download(storage_path('notes/' . $id . 'pdf'));
});

您可能希望将下载逻辑移动到控制器。并添加验证来检查文件是否存在但你已经了解了基本的思想