【问题标题】:Missing required parameter for file download route缺少文件下载路径所需的参数
【发布时间】:2018-02-13 09:23:41
【问题描述】:

路线:

 Route::get('download/{mixtape_file}', 'MixtapeController@download')-
    >name('download');

查看下载按钮:

 <a href="{{ route('download', $mixtape->mixtape_file) }}">
    <button class="btn btn-primary">Download</button>
 </a>

控制器下载功能:

 public function download($mixtape_file)
 {
    $mixtape = Mixtape::where('mixtape_file', '=', $mixtape_file)-
    >firstOrFail();
    $file = public_path('audio/' . $mixtape->mixtape_file);

    return response()->download($file);
 }

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    来自docs

    如果路由接受参数,你可以将它们作为第二个传递 方法的参数:

    $url = route('routeName', ['id' => 1]);
    

    所以在你的情况下它会是

    <a href="{{ route('download', ['mixtape_file'=> $mixtape->mixtape_file]) }}">
    

    【讨论】:

      【解决方案2】:

      您需要通过array 将您的数据pass 作为route() 辅助方法中的second 参数。

      <a href="{{ route('download', ['mixtape_file'=> $mixtape->mixtape_file]) }}">
      

      【讨论】:

        猜你喜欢
        • 2017-02-27
        • 2021-09-02
        • 2021-09-19
        • 2019-01-09
        • 2020-08-07
        • 2020-12-25
        • 1970-01-01
        • 2017-04-06
        • 2022-01-21
        相关资源
        最近更新 更多