Laravel 8 Tutorial - Create Zip File and Download

hi everyone welcome back to the laravel

air tutorial

in this video we are going to learn

about creating

and downloading the zip file so let's

see how can we create and download zip

file rvlate

so first of all let's create a new

controller so switch to the command


and here just type the command php


make colon controller

space controller name let's say

controller name is zip controller

now press enter

now run the application so just right

here php

artisan server

all right now let's create a folder

inside the public directory

so go to the project directory and just

go inside the public folder

and here let's create a new folder

and let's say folder name is my file

and just open this folder and inside

this folder let's copy some file so

i'm just going to my desktop and from


just copy these images okay so select

all and copy and now

just paste here

all right

now switch to the project and just open

zip controller so

go to the app directory then http


and from here just open zip controller

and inside this zip controller let's

create a function here

so just write here public function

and function name uh let's say function

name is

zip file all right

and inside this just

add here a zip variable

and new zip arching

and also add here use zip rgb

now create a variable for file name zip

file name

so just write here file name is equal to

add any uh zip file name let's say file

name is

my zip dot z right

and now just add here the if condition

dollar ship hello

open and inside this just right here

public underscore

path and here

just write to this dollar file name

inside this public path okay

and here just add the

comma then zip our chip

column column create

and now here equal equal to

all right and inside this if

just right here dollar files

is equal to file

column column also add here the file so

just write here

use file and now here

file colon colon uh files

and just right here public

underscore path and inside this just add

the folder name

which is this one my files okay

so just copy this folder name and

paste here

and now just add the forage so just

right here for each

and inside this download files


and inside this forage just right here

the relative

name in zip file

and now just add here a function based


and inside this just right right here

this variable value okay this one

and now dollar zip arrow

add file add file and inside this

just right here download value comma

this variable relative name


just paste here and

after that here just close the zip you

just write here dollar zip

and close okay

and here just return a response

so just right here return to response

has a response and just add here the

download functions just right here

download and inside this download

just add here public control score path

and here just add this file name

dollar file name

right now save this file and

let's create the route for this function

so just to go to the web.php

now just go inside the routes and just

open web.php

and here let's create a new route so

just write here

rau git and just add here the uri

let's say one is safe then controller


controller name is zip controller so

just right here receive

controller also add here the zip

controller so just right here this

like this use app http controllers

controller and now here

just add here colon colon

class comma

and here the function name which is zip

file you just copy this function name

and guest here all right

now save this file

all set so let's check it

so this to the browser and just go to

the url

class music okay now

press enter

you can see here now just click on this

icon and just

extract the file

okay and you can see here the file

okay so in this way you can create and


the zip file in laravel 8 so that's all

about creating zip and download

so thanks for watching this video and if

you still have any kind of question

you can ask me in the comment box don't

forget to subscribe my channel

thanks for watching