How to extend Laravel's Auth Guard class?

Viewed 10764

I'm trying to extend Laravel's Auth Guard class by one additional method, so I'm able to call Auth::myCustomMethod() at the end.

Following the documentation section Extending The Framework I'm stuck on how to exactly do this because the Guard class itself doesn't have an own IoC binding which I could override.

Here is some code demonstrating what I'm trying to do:

namespace Foobar\Extensions\Auth;

class Guard extends \Illuminate\Auth\Guard {

    public function myCustomMethod()
    {
        // ...
    }

}

Now how should I register the extended class Foobar\Extensions\Auth\Guard to be used instead of the original Illuminate\Auth\Guard so I'm able to call Auth::myCustomMethod() the same way as e.g. Auth::check()?

One way would be to replace the Auth alias in the app/config/app.php but I'm not sure if this is really the best way to solve this.

BTW: I'm using Laravel 4.1.

2 Answers
Related