hi everyone welcome back to the level 8
tutorial
in this video we are going to learn
about file upload
so let's see how can we upload a file in
laravel 8
so first of all let's create a new
controller
so switch to the command prompt and here
creating new controllers so just write
here php artisan
make colon controller
and space controller name let's say
controller name is
upload controller okay
now press enter controller created
now let's run the application so just
write here php artisan
right classes to the project
and just open the upload
controller so just go inside the app
directory
in http controllers and from here
just open upload controller
okay and here let's create a function
so just right here public
upload just right here okay
now let's create the route so
go to the wave.php inside the
routes directories just
routes and click on web.php and here
just create a route so just right here
route
okay at the uri
let's say upload controller name
controller name is upload controller so
just type here upload
okay not inside the single code just add
here the big bracket
right here upload
controller okay
and also add here you can see here
use http controllers and upload
controllers okay
this one now just add here
the column column class
right then comma function name which
is upload form so just write here
upload form all right now save this file
and now let's create this view so just
to go inside the view directory
and here create a new file
upload dot blade
dot php all right and here
just add the html5 wireless so just
press con
exclamation sign and press tab
and change the type let's say upload
file okay now at the bottom step
so go to the get bookstrap.com
and get started and just copy the css
and yes
just paste here all right
inside this body just add here container
empty okay
and inside this just add here the card
card
just right here file load
okay and here the card body
and inside this let's create a form
so just write here form
method is equal to post
and excel that's it blank
and click multipath form data
okay and then set this form
first of all add the date csrf
and here just add
okay and
input type is equal to file
plus
form comp control
okay and the name
file and id
okay
now create a submit button so just right
here button
type is equal to submit
class
btn
okay and inside this button just add
your text
upload okay
now save this file and let's check
so switch to the browser and here just
go to the url
you can see here the upload form all
right
now go to the upload controller and here
let's create a new function
so just write here public
function upload
upload file and here
you type this just pass here the request
dollar request
okay and inside this function simply
write here request
arrow file
and just store
the store inside the public tray just
right here store
and here simply write public
okay
you request file let's store in public
all right
and just return to message so just right
here
file has been
uploaded successfully
okay now save this file and
let's create a route for this function
so go to the web.php
and here just write route
post and add here the
upload controller name
load controller column
class and add the function name which is
upload file okay so let's copy paste
here
also add the name here so just write
your name
upload dot
upload file okay
now just copy this route name and
go to the upload blade upload.php file
and here
inside this form just add here inside
the action
curly bracket then route
single quote and just paste here the
route name upload
dot upload file all right
now save this file and let's check this
so switch to the browser
and just refresh the page now click on
browse just select a file let's
select this image this image first
click on open now click on upload
and you can see here the message file
has been uploaded successfully
okay so let's check this file uploaded
file so
go to the project directory now click on
the storage
app okay and you can see here the
uploaded image okay i want more images
to upload so
go to the upload url browse
now select another image click on open
upload file uploaded and here you can
see the
another file okay
so in this way you can upload files in
laravel yet
so that's all about file upload 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