【发布时间】:2014-01-09 04:19:10
【问题描述】:
我正在尝试通过另一种方法扩展 Laravel 的 Auth Guard 类,因此我可以在最后调用 Auth::myCustomMethod()。
按照文档部分Extending The Framework,我不知道如何准确地做到这一点,因为 Guard 类本身没有我可以覆盖的 IoC binding。
这里有一些代码展示了我正在尝试做的事情:
namespace Foobar\Extensions\Auth;
class Guard extends \Illuminate\Auth\Guard {
public function myCustomMethod()
{
// ...
}
}
现在我应该如何注册要使用的扩展类 Foobar\Extensions\Auth\Guard 而不是原来的 Illuminate\Auth\Guard,这样我就可以像调用 Auth::myCustomMethod() 一样使用例如Auth::check()?
一种方法是替换 app/config/app.php 中的 Auth 别名,但我不确定这是否真的是解决此问题的最佳方法。
顺便说一句:我使用的是 Laravel 4.1。
【问题讨论】:
标签: php authentication laravel extending