路由:
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:25:05
您需要通过pass将数据作为array帮助方法中的second参数。
<a href="{{ route('download', ['mixtape_file'=> $mixtape->mixtape_file]) }}">https://stackoverflow.com/questions/48763326
复制相似问题