Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KodaC's avatar
Level 1

Why I should add a disk in filesystems.php?

I found this tutorial: https://laraveldaily.com/post/laravel-file-uploads-save-filename-database-folder-url

I had a few questions about this. Maybe someone here can help me.

What is the advantage of creating a disk in filesystem.php instead of specifying in code

$avatar = $request->file('avatar')->store(options: 'avatars');

instead of (without Disk)

$avatar = $request->file('avatar')->store('avatars', 'public');

And is there a reason to work with Storage instead of asset in the blade? With Storage I get https://www.laravel.test, and with asset() I get https://backend.laravel.test (I have multiple Subdomains in my project)

And the last one: What do you think about Scoped Filesystem so that I use this instead of a new disk "avatars"? https://laravel.com/docs/10.x/filesystem#scoped-and-read-only-filesystems

0 likes
4 replies
Snapey's avatar

using a disk gives you one place to change (in config) if you decide that your files are better stored in another location.

Ideally you would store your images in a place that is not directly in your public folder.

Suppose you decided to move the images to a service like S3, using asset() means you can only ever resolve the images from the local public folder, whereas using a disk you could say

<img src="{{ Storage::disk('avatars')->url($user->avatar) }}" />

Then it would not matter what location the disk resolves to.

But a mention of @PovilasKorop might prompt him to comment about his post.

One further thought.... using a disk allows you to have different storage for production and development. Wheras production might use the cloud to store images, in local dev you could use your local disk.

1 like
KodaC's avatar
Level 1

Thank you @snapey On second thought, I totally agree with you

Suppose you decided to move the images to a service like S3, using asset() means you can only ever resolve the images from the local public folder

I thought I always have to use asset because of the subdomains. But i think in the end it doesn't matter if the image is called under backend.laravel.test or www.laravel.test. Or do you see a issue with subdomains?

Would you recommend to always use Storage when accessing a disk even if it is the public folder?

Ideally you would store your images in a place that is not directly in your public folder.

What would you recommend? Always use S3, or do you additionally define another folder like 'root' => storage_path('app/new_public/avatars'),

One further thought.... using a disk allows you to have different storage for production and development. Wheras production might use the cloud to store images, in local dev you could use your local disk.

Interesting. How would you do that? filesystems.php is usually overwritten when deploying from git. I didn't see anything in the documentation to distinguish disks from my environment with the same name.

Snapey's avatar
Snapey
Best Answer
Level 122

most projects are fine storing everything locally, however storing in somewhere like S3 saves you the burden of worrying about accidentally wiping the server storage.

filesystems.php can pull any of its information from the environment (or env file)

For instance, I have two disks here for two different types of asset

        'pods' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_PODS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

        'sigs' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_SIGS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

I'm only using S3 for all environments here, but I could change it like;

        'pods' => [
            'driver' => env('PODS_LOCATION'),
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_PODS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

and then in .env

PODS_LOCATION=local

or

PODS_LOCATION=s3

and do similar for any other settings that need to be environment specific

1 like

Please or to participate in this conversation.