Are you want to create zip file programmatically in laravel application then chumper/zipper composer package is help to generate zip file simply. Sometime we need to create zip file with images or other files, then also you have to give download as response.
In this article i will let you know how to generate zip file and download as response in laravel 5.5 application using chumper/zipper composer package. you have to just follow few step to generate zip file in laravel 5.5 application.
Install chumper/zipper Package:
first thing is to install composer package in our project. so install chumper/zipper composer package by following composer command in your laravel 5.5 application.
composer require chumper/zipper
After successfully install package, open config/app.php file and add service provider and alias.
'providers' => [
'aliases' => [
'Zipper' => 'Chumper\Zipper\Zipper'
Now we will add route for demo example, so simply add following route in your route file, here we will add "downloadZip" route and you can download created zip file:
Create HomeController method:
Here, we require to create new controller HomeController that will manage index method of route. So let's put bellow code.
class HomeController extends Controller
* Create a new controller instance.
* @return void
$files = glob(public_path('css/*'));
You can simply run this example and check it.
I hope you found your best.