Laravel - how to add global information like \Auth::user()

69 Views Asked by At

I have some custom middleware where I do my own authentication on some routes, and I want that middleware to make certain pieces of information available to the controllers, via an interface kind of like how you can do \Auth::user(); to get the user from anywhere.

What I've been doing it is adding it onto the $request object, but I suspect that's not best practice.

1

There are 1 best solutions below

0
On

Request class's $attributes property is perfect for that purpose.

/**
 * Custom parameters.
 *
 * @var ParameterBag
 */
public $attributes;