What should be the better way to store images or files to folder in laravel application

Viewed 54

I am doing a project using Laravel. Now, I have to store customers, users etc images both in the database and application folder. There are two ways to store images or files in laravel application.

  1. Inside public folder I can store.
  2. Another one is, inside storage/app/public

From these two ways, what should be better to do this. Would someone suggest me please? Thanks in advance.

2 Answers

There's not an enormous difference, but in general, it's better to put things in storage/app/public.

This allows you to give Laravel write permissions to the storage folder, while leaving its permissions on public as read-only. This is a bit more secure.

Generally, if your files need to be publicly available you it is recommended you use the laravel "Public Disk" which exposes yoursite.com/storage/ as a symbolic link to your_app/storage/app/public.

You can activate the public disk by running

php artisan storage:link

If files uploaded do not need to be directly accessed via the web, it is recommended that you use the "Local Driver" - these files are kept securely inside your_app/storage/app - one level up from the public folder and are not directly accessible by a web browser.

You are of course free to create any file structure in these directories as you need for your customers etc.

The Storage class helper is extremely useful.

Related