Tuesday, April 11, 2017

How to enrich/extend Auth class/data in Laravel 5?

In Laravel it's very useful to access Auth Facade after authentication in order to get user data like:

Auth::user()

What If during session and users interaction I'd like to enrich the object returned by the above call? Maybe assign some attributes to a user after he performed some action on my webapp?

E.g. A user performs a fast registration, and after while completes some other profile data. I'd like them to be available directly in Auth::user() instead of perform subsequent DB queries...

Maybe I'm missing some core concept?



via koalaok

Advertisement