How to upload file in Laravel

We will see how to upload file in Laravel in this tutorial. First I am going to create fresh laravel project

First you can download the composer and install it

Next you can download the Laravel y running the following command in your terminal

Now you can create your Laravel project named fileupload

To give permission to storage folder, you can run following command inside your project folder

Now you can run following command to start the server and you can open the application at http://127.0.0.1:8000

Now I am going to create controller and this controller will have actions index and store.

Now you can see the UploadController at App\Http\Controllers folder

Action index will show you the file uplaod form and action store is used to handle post rquest and store the upload file

Now you can add following code the store action

Above code will save the upload file to storage\app\public location

If you want to upload the files to public\images you can use the followng code

Now you can create the routes for actions. You can add the following code to routes\web.php

Next, we will create the view to upload file.
You can crate upload.blade.php file at resourcs\view and add the following code to make the file upload form

Now you can open the file uplaod page in http://localhost:8000/upload and upload the file

Once you upload the file you can see it in the public folder as shown in below image