php – Why you can't save files directly to the public folder (laravel)


Question about Lumen/Laravel file system:

The documentation contains a block describing the following: The public disk is intended for file sharing. By default, the public drive uses the local driver and stores files in storage/app/public. To make them available on the web, you need to create a symbolic link from public/storage to storage/app/public.

This raises the question: why do you need to link to another folder? Why can't you immediately save files to the public folder? There was an assumption that this would not allow you to access directly all the files that are in the public'ke, but this turned out not to be the case.


The documentation has the answer to your question.

This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.

That is, it is necessary to separate the public files of the project (css, js, index.php, robots.txt, etc.) and the files of a specific project instance (for example, pictures uploaded through the admin panel, etc.).

This is more correct in terms of project organization and will not create problems during automatic deployment.

BUT no one bothers you to save directly to the public directory, it is enough to change in config/filesystems.php

'root' => storage_path('app/public')


'root' => public_path('storage'),

on the public drive.

Scroll to Top