How to Upload Image to Public Folder in Laravel in best way?

We have learnt to upload single and multiple images to a Laravel application. However, in each case, we have to upload the images to a folder. In this tutorial, lets learn in detail on how to upload image to public folder in Laravel. Usually, there are two ways to upload a file in Laravel. We can either upload an image to the storage or public folder.

We can use the public_path method to upload the image in the public folder. This method has the storage location defined where the image will be moved to.

The storage location behind public_path is.

 public/images/file.png

We upload the image to this location using the method below.

$request->image->move(public_path('images'), $imageName);

We use this method in the Controller class, when we save image to the database.

Complete detail of using this method to upload image in Laravel is here. You can upload a single or multiple images using this method.

As a beginner we often get confused of the location our image will be stored in and how the public_path method will move our image at a specific location.

By default, Laravel defines the location behind the public_path method as stated above. So using the method to move any file or data stored the file or image at the defined path.