123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Http\Middleware;
- use Closure;
- use Illuminate\Contracts\Auth\Factory as Auth;
- class Authenticate
- {
-
- protected $auth;
-
- public function __construct(Auth $auth)
- {
- $this->auth = $auth;
- }
-
- public function handle($request, Closure $next, $guard = null)
- {
- if ($this->auth->guard($guard)->guest()) {
- $error = [
- 'message' => '身份校验失败,请重新登录',
- 'code' => '401',
- ];
- return response()->json($error);
- }
- return $next($request);
- }
- }
|