💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 错误信息提醒 ``` @if ($errors->any()) @foreach ($errors->all() as $error) <div class="alert alert-danger"> {{ $error }} </div> @endforeach @endif ``` ![](https://img.kancloud.cn/10/53/1053fc872356fd9ac99426d4ad2407f8_368x137.png) ### 提交返回的信息 ``` @if(session()->has("data")) <div class="alert alert-{{session("data")['class']}}"> {{ session('data')['msg'] }} </div> @endif ``` ![](https://img.kancloud.cn/c2/4b/c24b92026f7f16d3f7055d29190a934d_454x106.png) ###后端返回数据 ``` public function store(Request $request){ //检验数据 $this->checkdata($request->name,$request); $data=$request->only(["name","title"]); $config=json_encode($request->except(['_token','name','title'])); $data['config']=$config; $info=Config::where("name","=",$request->name)->first(); if($info){ $result=Config::where("name","=",$request->name)->update($data); }else{ $result=Config::create($data); } if($result){ session()->flash("data",['class'=>'success','msg'=>"更新成功"]); }else{ session()->flash("data",['class'=>'danger','msg'=>'更新失败']); } //dd($data); return redirect(route('admin.config.'.$request->name)); } ``` ### 提交数据验证 ``` /** * @param string $name * @param $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @author: hhygyl <jackhhy520@qq.com> * @name: checkdata * @describe:验证提交的数据 */ private function checkdata($name ="siteconfig",$request){ switch ($name){ case "information": $datavalidate=\Validator::make($request->all(),[ 'company' =>'required', 'address'=>'required', 'phone'=>'required' ],[ 'company.required'=>"公司名称不能为空", 'address.required'=>"公司地址不能为空", 'phone.required'=>'客服热线不能为空', ]); break; case "baidu": $datavalidate =\Validator::make( $request->all(),[ 'key' =>'required' ],[ 'key.required'=>"密钥不能为空" ]); break; default: $datavalidate = \Validator::make($request->all(),[ 'name' =>'required', 'title'=>'required', 'sitetitle'=>'required', 'domain'=>'required|url' ],[ 'name.required'=>"配置标识不能为空", 'title.required'=>"配置名称不能为空", 'sitetitle.required'=>'网站名称不能为空', 'domain.required'=>'网站域名不能为空', 'domain.url'=>'网址输入不正确', ]); break; } /** * 数据验证失败提示 */ if($datavalidate->fails()){ return redirect(route('admin.config.'.$request->name)) ->withErrors($datavalidate) ->withInput(); } } ```