Friday, March 31, 2017

Is it ok to change public storage folder name from 'public/storage' to 'public/public'?

Laravel recommends here to create symlink from public/storage to storage/app/public. I'm looking for some inputs on whether renaming public/storage to public/public would cause any issues in other configurations or packages.

I am doing this because all my filenames in db are relative to storage/app folder. I store it that way since I can then uniformly retrieve any file using storage_path() helper. For example:

  1. Protected file: storage/app/internal/secret.doc => filename in db = internal/secret.doc
  2. Public file: storage/app/public/common.doc => filename in db = public/common.doc

Then to retrieve them:

// get filename 'internal/secret.doc' or 'public/common.doc'
$filename = DB::table('files')->find(1)->value('name'); // find file where id=1 and get only the name field
$file = storage_path('app/'.$filename);

This way I don't have to wonder whether I need to add public/ folder while retrieving a specific file. Also when I use asset() helper to generate urls to public files, again I can simply say:

$url = asset($filename)`;

Whereas, if I continue to use public/storage as the symlinked folder then I would have to do:

$temp_filename = str_replace('public/', '', $filename);
$url = asset('storage/'.$temp_filename);

Let me know if you have a different take or spot some issues with the renaming.



via Sriram Ranganathan

Advertisement