du521521521 2017-03-12 06:00
浏览 176
已采纳

如何扩展Laravel Storage外观?

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:

$this->app->bind('MyStorage',function($app){
    return new MyStorage($app);
});

And facade is:

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

When using it:

use Namespace\MyStorage\MyStorageFacade as MyStorage;
MyStorage::disk('local');

I get this error:

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

Also tried to extend MyStorage form Illuminate\Filesystem\Filesystem and got the same error in other way:

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

  • 写回答

2条回答 默认 最新

  • dongyou6795 2017-03-12 06:29
    关注

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

    class MyStorage extends \Illuminate\Filesystem\FilesystemManager {
        ....
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀