Omid Omid - 1 year ago 101
PHP Question

How to extend Laravel Storage facade?

Without knowing how Laravel facades work, based on my PHP knowledge, I tried to extend Storage facade to add some new functionalities.

I have this code:

class MyStorageFacade extends Facade {
* Get the binding in the IoC container
* @return string
protected static function getFacadeAccessor()
return 'MyStorage'; // the IoC binding.

While booting service provider:

return new MyStorage($app);

And facade is:

class MyStorage extends \Illuminate\Support\Facades\Storage{

When using it:

use Namespace\MyStorage\MyStorageFacade as MyStorage;

I get this error:

FatalThrowableError in Facade.php line 237: Call to undefined method Namespace\MyStorage\MyStorage::disk()

Also tried to extend
and got the same error in other way:

BadMethodCallException in Macroable.php line 74:
Method disk does not exist.

Answer Source

Your MyStorage class needs to extend FilesystemManager not the Storage facade class.

class MyStorage extends \Illuminate\Filesystem\FilesystemManager {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download