Search code examples
phplaravelintervention

Correct location for static image used in Intervention


Let's say I have a Job that generates an avatar image through Intervention with the username on top of a static default background image. This background image should be available for each project member, so it should life somewhere in the repo.

My question is: where does this static background image life?

When I take a look at the Laravel docs about the Directory Structure I conclude that:

  • It should not life in the public directory, since it does not have to be publicly accessible (the image itself is never used without the username on it)

    The public directory contains the index.php file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images, JavaScript, and CSS.

  • It should not life in the storage directory, since this folder seems to be for generated stuff (and is subject to overwrites)

    The storage directory contains your compiled Blade templates, file based sessions, file caches, and other files generated by the framework. [...]

  • It could maybe life in the resources directory, since this directory contains "raw, un-compiled assets". But the fact that images are not used as an example it makes me doubt.

    The resources directory contains your views as well as your raw, un-compiled assets such as LESS, SASS, or JavaScript. This directory also houses all of your language files.

What are your opinions on this question?


Solution

  • First off, your application shouldn't depend on the file being in the same filesystem. You should use the Laravel Storage API, since that way you can easily store the files on a third party storage solution such as Amazon S3 without having to change anything other than a config setting.

    With the local driver, the files would default to being stored under storage/app, which I would consider the correct location. It's actually recommended that if a file needs to be publicly accessible, it should be stored in storage/app/public/, which should be symlinked to public/.

    As you have observed, the public directory is for anything that needs to be publicly accessible, including compiled Less/Sass, JavaScript and images. The resources directory is for their uncompiled counterparts, so your Less/Sass files and JavaScript should go there before being processed by Mix. The storage folder is for more general file storage use, but I would have a look at the possibility of storing these files with a third party service.