文件下载 下载次数自增

视图:
如果是是target=”_blank“ 那href就是规定在何处打开链接文档 ,如果target=“download” 那href就是规定被下载的超链接目标。

下载

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');
    }

你可能感兴趣的:(文件下载 下载次数自增)