0
votes

I'm trying to store a file in the public folder storage/app/public/ but for some reason Laravel just seems to put it in the private storage/app/ folder.

If I understand correctly I'm supposed to just set the visibility to 'public' but that doesn't seem to change anything:

Storage::put($fileName, file_get_contents($file), 'public');

When I call getVisibility I get public so that seems to work fine:

Storage::getVisibility($fileName); // public

These are the settings in my filesystems.php:

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

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

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_KEY'),
        'secret' => env('AWS_SECRET'),
        'region' => env('AWS_REGION'),
        'bucket' => env('AWS_BUCKET'),
    ],

],
1

1 Answers

1
votes

When you call Storage::put, Laravel will use the default disk which is 'local'.

The local disk stores files at its root: storage_path('app'). The visibility has nothing with where the file should be stored.

You need to choose the public disk which will store the files at its root: storage_path('app/public'),

To do that, you need to tell Laravel which disk to use when uploading the file. Basically change your code to this:

Storage::disk('public')->put($fileName, file_get_contents($file), 'public');