namespace App\Http\Controllers\Admin\Operations;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Zip;
use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Str;
trait DownloadOperation
{
protected function download($id)
{
- $id = $this->crud->getCurrentEntryId() ?? $id;
- $entry=$this->crud->getEntry($id);
- $entry->compile();
+ $compilepath = protected_path('quiz/final/' . $id);
+ $entry = $this->crud->getEntry($id);
+ $entry->compile($compilepath);
+
+ $fname = Str::slug($id . ' ' . $entry->getAttribute('title')) . '.zip';
+ $dest = protected_path('quiz/download/' . $fname);
+
+ Zip::archive($compilepath, $dest);
+
+ return response(null)->header('Content-Type', 'application/zip')
+ ->header('Content-Disposition', 'attachment; filename="' . $fname . '"')
+ ->header('X-Sendfile', $dest);
}
}