Implementing the zipstream in our application but it gives me an error when zipping the exported data.
So far this what I have done
- composer require stechstudio/laravel-zipstream
- Copy & paste the example provided
- When I tried to export, it gives me an error "Class ‘STSZipStreamFacadesZip’ not found"
- Check my config/app.php, manually added the STSZipStreamZipStreamServiceProvider::class
Im following the instructions here https://github.com/stechstudio/laravel-zipstream?tab=readme-ov-file
Versions
- Using version ^4.14 for stechstudio/laravel-zipstream
- Laravel Framework 6.20.44
- php version 7.4.9
Controller
use STSZipStreamFacadesZip;
$zip = Zip::create('my_files.zip');
$zip->addFile('file1.txt', 'contents of file1');
$zip->addFileFromPath('path/to/file2.pdf', 'file2.pdf');
return response()->stream(function () use ($zip) {
$zip->finish();
}, 200, [
'Content-Type' => 'application/zip',
'Content-Disposition' => 'attachment; filename="my_files.zip"',
]);
Tried the ff but still not working
- Check the composer.json, the packaged has been installed
- execute the ff commands: php artisan config:clear & php artisan cache:clear
- composer dump-autoload
How do I fix the error "Class ‘STSZipStreamFacadesZip’ not found"?"
2
Answers
im new to this but sometimes
php artisan config:clear
php artisan cache:clear
helped me.
and make sure you have this line in your composer.json
"require": {
"stechstudio/laravel-zipstream": "^4.14"
}
then use: composer dump-autoload
The
use STSZipStreamFacadesZip;
facade is described as a breaking change in version ^5 of laravel-zipstream (See the release notes here).You’re using version ^4 so you need to access the facade a different way…