0

I have some problems with authentication on my middleware file. I'm logging on which page is client last seen, like so:

public function handle(Request $request, Closure $next)
    {
        Activity::create(['user_id' => Auth::id(), 'ip_id' => SecureAgent::getIP(), 'action' => $request->method(), 'page' => $request->path()]);
        

        return $next($request);
    }

File in Karnel is added in $middleware;

The problem is that Auth::id() is not working, only NULL. I have logged in with passport, set my token and redirect to profile page, everything is working fine except this middleware.

krimo
  • 666
  • 2
  • 8
  • 27
Rade Ilijev
  • 51
  • 1
  • 10

1 Answers1

0

The Auth::user() will give you access to current loggined user in system,
you need to change 'user_id' => Auth::id() to 'user_id' => Auth::user()->id

Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36