protectedfunctionunauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
returnresponse()->json(['error' => 'Unauthenticated.'], 401);
}
// return a plain 401 response even when not a json callreturnresponse('Unauthenticated.', 401);
}