My query return results from database as comma separated values: 1,2,3..etc
Then I'm trying to make a button for download and should select 1 or more documents to download ( based on if is 1 id or multiple ).
So button with one file looks like this
<a href="users/files/download/2?_token=SivFIl3kKuflAvIyYJFGKdovJHTlqpjObN2nMFbQ">Download Now</a>
and button where the query return multiple id's looks like this ( notice the 2,3
before the token )
<a href="users/files/download/2,3?_token=SivFIl3kKuflAvIyYJFGKdovJHTlqpjObN2nMFbQ">Download Now</a>
This I add to the routes.php
Route::get('/users/files/download/{fileId}', 'UsersController@getDownload');
And this to the controller
public function getDownload($fileId)
{
$file = Documents::findOrFail($fileId);
$file = public_path(). "/uploads/" . $file->document_path;
return Response::download($file, 'filename.pdf');
}
Currently no matter which button I click I've got
Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [Documents].
What is this means? The model is there. This is the Documents model
class Documents extends Eloquent
{
protected $table = 'documents';
protected $primaryKey = 'id';
public $timestamps = false;
}
And how I can select all documents ID's when they are multiple?
Update: current code
$file = Documents::findOrFail([$fileId]);
$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($file as $files) {
$path = public_path(). "/uploads/" . $files['document_path'];
if(file_exists($path)){
$zip->addFromString(basename($path), file_get_contents($path));
}
else{ echo"file does not exist"; }
}
$zip->close();