反思代码优化点:trycatch 验证类 封装用户变量

1.使用try catch进行捕获异常
2.使用验证类与场景结合,完成快速验证数据合法性
3. 封装使用对象,这样用起来很方便!$request->user = $user;

if ($token) {
                $user = User::where('token', $token)->find();
                if ($user) {
                    $request->user = $user;
                } else {
                    throw new Exception("登录失效,请重新登录", 203);
                }
                return $next($request);
            } else {
                throw new Exception('登录失效,请重新登录', 203);
            }```


猜你喜欢

转载自blog.csdn.net/fujian9544/article/details/111403042