Laravel Public Files with No Symlink: in Public Folder Instead of Storage

By default, Laravel stores the uploaded public files in the storage/app/public, and you should create a so-called "symbolic link" with the Artisan command "php artisan storage:link". But what if you don't have SSH access to the Terminal and can't run this command?

One of the solutions is to store the public files in the /public folder without any storage/ or symlinks.

To do that, you need to change the configuration of your local public disk.

config/filesystems.php:

'disks' => [
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
'throw' => false,
],

Then you could use this command to access the files in public/images, for example:

$path = $request->file('avatar')->store(
'images/something.png', 'public'
);

That file will be stored in public/images/something.png.

Assuming your web-server document root is correctly set to the public/ folder, you can access that file as https://yourwebsite.com/images/something.png.

Notice: be careful not to override the default files that come with Laravel in the /public folder. Make sure to always create subfolders for your custom uploaded files.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1057 lessons, total 42 h 44 min)
  • 79 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials