Laravel Download files from database

This is my question:
I’ve a system where the user can see the information about a particular post; for expample in the section “Sales” the user can see all the information about one product; and in every product, the user can donwload the files, like download a PDF; or mp3, in this case, a mp3 file:
Well, the system save all the records about the files that the user downloaded, and after save the records, download the file:
My exactly problem is, the record of the files donwloaded save in database, but, never start the download; I’ve 2 relations, and are, a audiobook can have multiples download, but, a donwload, just have 1 audiobook:

public function downloads() //One download for one audiobook
{
    return $this->hasMany('/bdc/AudiobookDownload');
}

public function audiobooks() //Multiples download for one audiobook
{
    return $this->belongsTo('/bdc/AudioBook');
}

This is my code, where the download suposse start:

public function downloadAudiobook($id)
{
        if (Auth::user())
        {
            $userCheck = Auth::user()->$id;
            $download = AudiobookDownload::where(['user_id' => $userCheck, 'audiobooks_id' => $id])->first();
            if (empty($download->user_id))
            {
                $user_id = Auth::user()->id;
                $audiobooks_id = $id;
                $download = new AudiobookDownload;
                $download->user_id = $user_id;
                $download->audiobooks_id = $audiobooks_id;
                $download->save();
            }
        $download = public_path().'/uploads/audiobooks/audiobook_location/' . $download->audiobooks_id .'.m‌​p3';
            return response()->download($download);
        }
        else
        {
            return redirect()->route('login')->with('validate', 'Por favor inicia sesión para descargar este audiolibro');
        }
}

All the files are inside a folder, inside the public folder of the proyect, and the route of the folder are in DB:

$table->string('audiobook_location')->nullable();

And I got this error:

(1/1) FileNotFoundException The file
“/home/vagrant/Code/BDC/public/uploads/audiobooks/audiobook_location/1.m‌​p3”
does not exist

Where is 1.mp3, have to be the name of the file that the user is trying download

I need download just one file, of one post; if someone can help me, I’ll be really grateful!

You haven’t shown your routes, but I am guessing you have one something like:

Route::get('/some/path/download/{id}', '[email protected]');

And I think the $id passed to your downloadAudiobook method must be the id of an audiobook?

First, this line does not make sense, since the $id here is not related to the logged in user:

$userCheck = Auth::user()->$id;

I think you want the user ID of the logged in user:

$userCheck = Auth::user()->id;

Next – you haven’t shown us your Audiobook model, but I am assuming you must have a filename column – or is that the audiobook_location you mention? So you can retrieve the audibook record and use the filename in your download response:

$audiobook = AudioBook::find($id);
$download = public_path().'/uploads/audiobooks/audiobook_location/' . $audiobook->audiobook_location;

Complete code:

public function downloadAudiobook($id)
{
        if (Auth::user())
        {
            $userID = Auth::user()->id;
            $download = AudiobookDownload::where(['user_id' => $userID, 'audiobooks_id' => $id])->first();
            if (empty($download->user_id))
            {
                $download = new AudiobookDownload;
                $download->user_id = $user_id;
                $download->audiobooks_id = $id;
                $download->save();
            }

            $audiobook = AudioBook::find($id);
            $download = public_path().'/uploads/audiobooks/audiobook_location/' . $audiobook->audiobook_location;
            return response()->download($download);
        }
        else
        {
            return redirect()->route('login')->with('validate', 'Por favor inicia sesión para descargar este audiolibro');
        }
}