Laravel - How to add values to request array from middleware

https://laraveldaily.com/how-to-artificially-add-values-to-request-array/

Middleware file:

$request->request->add(['user' => $user]);

Controller file:

$name = $request->user->name;


Example:

Middleware file:

class MyMiddleware
{
    public function handle($request, Closure $next)
    {
        $user = User::whereToken($request->user_token)->first();

        if (is_null($user)) throw new InvalidUserTokenException();

        $request->request->add(['user' => $user]);

        return $next($request);
    }
}

Controller file:

class MyController extends Controller
{
    public function __construct()
    {
        $this->middleware('mymiddleware');
    }

    public function store(Request $request)
    {
        return $request->user;
    }
}