视图:
如果是是target=”_blank“ 那href就是规定在何处打开链接文档 ,如果target=“download” 那href就是规定被下载的超链接目标。
<a href="{{$v->file}}" target="download" class="btn-play" data-id="{{$v->id}}">下载</a>
js:
$(".btn-play").click(function() {
var id = $(this).data('id');
$.get('/w/subject/download_count'+'/'+id);
})
路由:
Route::get('/download_count/{id}', 'SubjectController@getDownloadCount')->name('get_download_count');
控制器方法:
public function getDownloadCount(Request $request, $id)
{
Subject::incrementDownloadCountById($id);
return $this->responseJSON([], 0, 'ok');
}
模型:数据表里download_count字段自增
public static function incrementDownloadCountById($id)
{
return self::where('id', $id)->increment('download_count');
}