I want to make an entry in the logs of user actions:

switch ($request->segment(2)) { case 'login': $request->method() != "POST" ?: \Log::info(auth()->user()->id . ' user is login'); break; case 'logout': \Log::info(auth()->user()->id . ' user is logout'); break; case 'register': $request->method() != "POST" ?: \Log::info(auth()->user()->id . ' is register'); break; } return $next($request); 

When the login action gives an error:

Trying to get property of non-object

Added $response = $next($request); Everything works, but I would like to improve the code, how can I do it?

    1 answer 1

    I think the fact is that if the user does not already exist, when trying to execute auth()->user()->id , an error occurs. In short, it is more correct to check if there is a user in the system.