全端页面 PHP tp6 中件件的验证token


class Check
{

public function handle($request, \Closure $next)
{
$token = $request->get('token');
// print_r($token);die();
if (empty($token)) {
echo 'token不存在,请登录';
die();
}
$result = Token::verifyToken($token);
// print_r($result);die();
if (!$result) {
echo 'token验证错误(不是本人操作)';
die();
}

return $next($request);
}

}

路由
Route::group(function (){
Route::post('phone', 'login/phone');
})->middleware(\app\exam\middleware\Check::class);
tp6