skip to Main Content

Implementing the zipstream in our application but it gives me an error when zipping the exported data.

So far this what I have done

  1. composer require stechstudio/laravel-zipstream
  2. Copy & paste the example provided
  3. When I tried to export, it gives me an error "Class ‘STSZipStreamFacadesZip’ not found"
  4. 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

  1. Using version ^4.14 for stechstudio/laravel-zipstream
  2. Laravel Framework 6.20.44
  3. 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

  1. Check the composer.json, the packaged has been installed
  2. execute the ff commands: php artisan config:clear & php artisan cache:clear
  3. composer dump-autoload

How do I fix the error "Class ‘STSZipStreamFacadesZip’ not found"?"

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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…

    // use STSZipStreamFacadesZip;
    // becomes:
    use STSZipStreamZipStreamFacade;
    
    // Zip::create(...);
    // becomes:
    ZipStreamFacade::create(...);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search