v2board/app/Http/Middleware/Client.php

31 lines
627 B
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
namespace App\Http\Middleware;
use Closure;
use App\Models\User;
class Client
{
/**
* Handle an incoming request.
*
2020-01-11 13:36:52 +08:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
2019-10-29 15:33:36 +08:00
* @return mixed
*/
public function handle($request, Closure $next)
{
$token = $request->input('token');
if (empty($token)) {
2019-12-10 10:55:49 +08:00
abort(403, 'token is null');
2019-10-29 15:33:36 +08:00
}
$user = User::where('token', $token)->first();
if (!$user) {
2019-12-10 10:55:49 +08:00
abort(403, 'token is error');
2019-10-29 15:33:36 +08:00
}
$request->user = $user;
return $next($request);
}
}