I am trying to create last user activity, and i've been reading some instructions on middlewares but i am confused, i previously built middleware for role check and that successfully works when i put middleware in
$routeMiddleware because that should be routed middleware, now i am reading on and there is
global middleware which says:
If you want a middleware to run during every HTTP request to your application, list the middleware class in the $middleware property of your app/Http/Kernel.php class.
So this means middleware would run every possible time, which i need.
So i created middleware
I registered middleware in global middleware in
protected $middleware = [ \App\Http\Middleware\LastActivity::class, ];
And if i try to simply do this in middleware:
$user = Auth::user(); dd($user)
I get null or false, as user is not loged in.
But if i move middleware to
protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\LastActivity::class, ];
Than it works, so why it doesn't catch in global? Am i missing something here, i still didn't tested with api requests but i'm afraid it won't work per explanation i read on middleware page. But i will need it for api requests too, so global middleware would be solution.