app\Exceptions\Handler.php
新增如下內容:
/**
* @param \Illuminate\Http\Request $request
* @param AuthenticationException $exception
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['message' => 'The token is invalid.'], 401);
}
// return redirect()->guest('login');
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結