lcjury's avatar

Using /images instead of /storage/images to upload files to local storage

With the default configuration, laravel uploads images to the public disk: storage/app/public/, when using the storage:link command, we get a symbolic link from public/storage to storage/app/public

There are 2 downsides with this approach:

  1. to access files through the browser you use the url: yoursite.com/storage/path_to_file
  2. you have to manually add the storage portion to your links

I'm doing something wrong?, Is there any "laravel way" of getting rid of the storage part?, I could change the storage configuration, I could store my images inside a folder (let's say logos), and then do a symbolic link from public/logos to storage/app/public/logos

The downside of this:

I have to remember this when somebody else installs the project in their computer (or add a new artisan command to do it) or when deploying.

0 likes
10 replies
lcjury's avatar

When using the asset helper I'm still stuck with the storage in the url.

jlrdw's avatar
$url = asset('img/photo.jpg');

From docs, I do not see storage.

Have you actually re-read file storage and browsed over the helpers and double checked your code.

I've never had the word storage for an image.

Cronix's avatar

You can change it in /config/filesystems.php.

Just configure root to upload to public_path() (or specifically where you want) instead of storage_path('app'). Then uploads will be placed directly in /public, and you can use the asset helpers without having to manually enter "storage" in the url.

1 like
lcjury's avatar

When you use the FileUploader class they use the filestorage disks configured. By default they place the files on storage/app/public. That folder is not public to the world, so, laravel recommend doing a symbolic link from public/storage to storage/app/public.

I want to put a link from public/x to storage/app/public/x, I'm asking if laravel has some standard way of doing this, maybe an undocumented option on tinker, idk.

Cronix's avatar

I want to put a link from public/x to storage/app/public/x, I'm asking if laravel has some standard way of doing this, maybe an undocumented option on tinker, idk.

The only link laravel makes out of the box is the default one you are trying not to use, after you run artisan storage:link. Of course, you can manually make a link in linux. I'm not sure the point though, going by your last post. Then instead of asset('storage/some-file.txt') you'll have asset('x/some-file.txt'). you'll have to manually enter x instead of storage.

If you just change the location of the uploads like I suggested originally, then you could just use asset('some-file.txt') which would be http://yoursite.com/some-file.txt which is what I thought you wanted (no mention of storage in the url).

lcjury's avatar

Yeah, your solution works, I was replying to jlrdw, thanks :).

jlrdw's avatar

When you use the FileUploader class they use the filestorage disks configured. By default they place the files on storage/app/public.

There is also MOVE

$file->move($destinationPath, $newname);

Taylor is not going to restrict where you place your files. Or the names you choose for the folders.

Snapey's avatar

why is it such a concern that files are at /storage/logos and not just /logos?

who cares? noone sees this?

Are you getting hung up on something thats not really an issue except in you mental model of how the site should be structured

(sorry, just playing devils advocate)

Please or to participate in this conversation.