#file-upload #laravel #tricks

File Upload Made Easy in Laravel

Here I am working under the impression that, the setup is ready, tables and migrations are there, form and view files are good to go.

We will focus here on the main uploading part, ones the file reach the controller. I am also skipping the validation part for the file as we will take it in consideration some other time.

So, as per me the best approach is to put the entire path of the file in database, instead of just putting the name of the uploaded file.

$fileLink = url(Storage::url(Storage::put('public/files', request('file'))));

The above piece of code will put the file in storage/app/public/files, with a uuid name and will return with the complete URL foe the file.

Before be able to access this file in browser by the provided link, you need to do one more thing, create the symlink from storage to public by running the following command

php artisan storage:link

and now we are good to go.


Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.