路由:
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);
}发布于 2018-02-13 09:27:07
来自文档
如果路由接受参数,则可以将它们作为第二个参数传递给该方法:
$url = route('routeName', ['id' => 1]);所以在你的情况下
<a href="{{ route('download', ['mixtape_file'=> $mixtape->mixtape_file]) }}">发布于 2018-02-13 09:25:05
您需要通过pass将数据作为array帮助方法中的second参数。
<a href="{{ route('download', ['mixtape_file'=> $mixtape->mixtape_file]) }}">https://stackoverflow.com/questions/48763326
复制相似问题