🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1. laravel常见引入 ``` ~~~ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Log; //记录日志 use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Validator; //验证参数 ~~~ ``` 2. 对接受字段经行验证 ``` $validator = Validator::make($request->all(), [ 'id'=> 'required|exists:mysql.oftens,id', ], [ 'id.required' => '模版不存在' ]); if ($validator->fails()) { $sSMG = getFirstKey($validator->getMessageBag()); return json_response('', $sSMG, 401); } ``` 3. 异常处理 ``` try { //逻辑处理(非数据库异常) } catch ( \Exception $exception ) { Log::info($exception->getMessage()); return json_response('',env('ERROR_MESSAGE'),env('ERROR_CODE')); } ``` ``` try { DB::beginTransaction(); //开启事务 //逻辑处理(数据库异常) DB::commit(); //提交 } catch ( \Exception $exception ) { DB::rollBack(); //回滚 Log::info($exception->getMessage()); return json_response('',env('ERROR_MESSAGE'),env('ERROR_CODE')); } ``` 4. 日志记录 参考博客:https://blog.csdn.net/wlzx120/article/details/77161679 5. 表单提交---419错误的处理 参考博客:https://blog.csdn.net/m0\_62229785/article/details/124937522 6. 登录---验证码 参考博客:https://blog.csdn.net/handsomezls/article/details/121231816 7.登录---Jwt验证 参考:项目技术->Jwt的应用 8.获取唯一识别码 参考博客:https://www.blog8090.com/untitled-4/](https://www.blog8090.com/untitled-4/ 9.创建公共方法的文件 参考博客:https://blog.csdn.net/qq\_38778882/article/details/108756970