Search code examples
laraveldownloadresponseinsert-update

Increment column before response download - Laravel


I want to simply increment a column for each download but it adds 2 or more instead of 1. Here is my code:

 public function download(Music $music)
{ 

    $music->increment('downloads');


    $file=$music->getFilePath();
    return response()->download($file,$music->title);
}

However, if I remove response()->download... line it works correctly. What's the problem and how to solve it?


Solution

    • Check if the download function is being called multiple times, not just once.
    • Implement response download function by yourself.

    [update]

    IDM issue. Can be solved by separating increment and download routes.