Overriding Laravel authentication controllers
This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.
I spent a couple of hours over the weekend re-writing the authentication controllers that run StudentVIP. They were written a long time ago in the early Laravel 4 days (and originally ran on the now-defunct Sentry package). It was time to bring them back into line with the default scaffolding that ships with Laravel to make it easier for everyone that works on the app.
I noticed that the logout method doesn't really provide any hooks for you to customise what happens. In my use-case we needed to customise this a little bit, but still wanted to defer the core logging-out logic back to the framework.
Turns out that PHP allows you to import methods from a trait with an alias, which lets you write a method of the same name and then call it. This is helpful because it effectively allows you to override methods provided by a trait and still use them, much like parent::
would let you call a parent classes method.
With the alias in place you can then call that alias on the class and it it will work as you expect.