JR E
JR E

Reputation: 23

Fetch Laravel Storage files that are in the storage/folder directory not in storage/app/directory

I'm attempting to pull in a certs file from the directory /storage/certs/certexample.pem in my laravel 6 application.

Whenever I try to run the command:

Storage::get('storage/certs/certexample.pem'))

or use

storage_path('certs')

to fetch the full path I get the error:

League\Flysystem\FileNotFoundException: File not found at path:

The file does exist and I can cat it out on the terminal so there must be something I'm missing.

My filesystem config looks like this:

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

I've tried adding in another disk called 'certs' that has storage_path('certs') set however this doesn't seem to help.

Since the file is only ever placed on the server and the app isn't writing it I don't need to write the file using Storage as I've seen in the docs. Is there a way to pull the certsexample.pem file (or a similar file) in this manner or am I missing something with Laravel's Storage functionality?

Update: After attempting to get a folder to be accessed outside of storage/app with no luck I ended up using the sotrage/app/certs directory and accessing it with storage_path('app/certs').

Upvotes: 1

Views: 1402

Answers (1)

BANKAI
BANKAI

Reputation: 90

I had the same problem. I updated config file in config/filesystems.php and added my folder in /storage:

'disks' => [

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

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

    //my custom directory in storage folder
    'orders' => [
        'driver' => 'local',
        'root' => storage_path('egrn/orders'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],
    //...default config code

    ],

And I got the file like:

$storage = Storage::disk('orders')
->get('/kv66cba66ca6cf667995888bf12cc4d25d.xml');

Full path is /storage/egrn/orders/kv66cba66ca6cf667995888bf12cc4d25d.xml

Upvotes: 1

Related Questions