Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Get storage disk path

Tags:

php

laravel

I have created a new storage disk for the public uploads. I use it like this:

Storage::disk('uploads')->get(...);

But I am trying to figure out a way to get the path to the disk itself, I have spent some considerable time wondering between the framework files, but couldn't find what I am looking for. I want to use it in a scenario like so:

$icon = $request->file('icon')->store('icons', 'uploads');
Image::make(Storage::disk('uploads')->path($icon))->resize(...)->save();

So, how to get a storage disk's path ?

like image 512
Dewan159 Avatar asked Oct 03 '16 20:10

Dewan159


People also ask

Where is storage disk path in Laravel?

$icon = $request->file('icon')->store('icons', 'uploads'); Image::make(Storage::disk('uploads')->path($icon))->resize(...)- >save();

How can I get storage path in Laravel 7?

You can use the storage_path(); function to get storage folder path.

How do I save to storage folder in Laravel?

Now, if you need to change the directory and store into the storage folder directly, you need to change something in the filesystems. php file. 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), ], Here, this line of code 'root' => storage_path('app'), responsible to define where to store.


2 Answers

There is a function for this!

Storage::disk('uploads')->path('/');

https://laravel.com/api/5.8/Illuminate/Filesystem/FilesystemAdapter.html#method_path

Looks like this has been there since 5.4! I never noticed...

like image 122
PiTheNumber Avatar answered Sep 16 '22 15:09

PiTheNumber


After extra search I found that I can use the following:

$path = Storage::disk('uploads')->getAdapter()->getPathPrefix();

But still, isn't a "->path()" method is a given here or what!

like image 36
Dewan159 Avatar answered Sep 20 '22 15:09

Dewan159