Laravel5.8入门与实战-安全与优化
表单验证提示信息
if ($result===true || $result>0) { $request->session()->flash('data',['class'=>'success','msg'=>'更新成功']); }else{ $request->session()->flash('data',['class'=>'danger','msg'=>'更新失败']); } return redirect(route('admin.config.siteconfig')); }表单验证blade里面
@if (session()->has('data')) <div class="alert alert-{{session('data')['class']}}"> {{session('data')['msg']}} </div> @endif数据验证
private function checkdata($name='siteconfig',$request){ switch($name){ case 'infomation': $datavalidate = $request->validate([ 'company'=>'required', 'address'=>'required', 'phone'=>'required', ],[ 'company.required'=>'公司名称不能为空', 'address.required'=>'地址不能为空', 'phone.required'=>'客服热线不能为空',]); break; case 'baidu': $datavalidate = $request->validate([ 'key'=>'required', ],[ 'key.required'=>'百度密钥不能为空', ]); break; default: $datavalidate = $request->validate([ 'name'=>'required', 'tittle'=>'required', 'sitetittle'=>'required', 'domain'=>'required|url', ],[ 'name.required'=>'配置标识不能为空', 'tittle.required'=>'配置名称不能为空', 'sitetittle.required'=>'网站名称不能为空', 'domain.required'=>'网站域名不能为空', 'domain.url'=>'网址输入不正确', ]); break;