【发布时间】: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);
}
【问题讨论】: