How to call the parent of an overridden trait method?
Hi,
I've overwritten the method "getLogout()" from the AuthenticatesUsers-Trait inside the AuthController-class. My problem is, that I'm not sure how to call the parent method inside the trait after my custom stuff?
That wouldn't affect your code, since you override the function from the trait, so the trait can be updated to whatever, your code will still work when you override the traits function
If you copy and paste the trait's method you will not be able to make use of any future updates to Laravel's auth code. Here is my solution:
In this example i want to override 'logout' method.
class LoginController extends Controller
{
use AuthenticatesUsers {
logout as protected parent_logout;
}
// This is my method to add custom code before logout
public function logout(Request $request)
{
// Custom code goes here
// Finally call the trait's logout method
return $this->parent_logout($request);
}
}
This way you can add your customization and also get the benefits of updates to the laravel package.