/* * @会员相关信息编辑修改 */ public function update(Request $request, $id) { $vips = User::find($id); if ($request->isMethod('post')) { $roles = [ 'name' => 'required|max:5', 'age' => 'required|numeric', 'id_card' => 'required|identitycards', 'telphone' => 'required|telphone', ]; $msg = [ 'name.required' => '请填写姓名', 'name.max' => '姓名格式有误', 'age.required' => '请填写年龄', 'age.numeric' => '年龄格式有误', 'id_card.required' => '请填写身份证号码', 'id_card.identitycards' => '身份证号码格式有误', 'telphone.required' => '请填写手机号码', 'telphone.telphone' => '手机号码格式有误', ]; $validator = \Validator::make($request->all(), $roles, $msg); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withinput(); } $name = $request->get('name'); $age = $request->get('age'); $sex = $request->get('sex'); $telphone = $request->get('telphone'); $id_card = $request->get('id_card'); // 排除自己的查找,根据id,验证规则也去除 $res = User::where('telphone', '!=', $vips->telphone) ->where('id_card', '!=', $vips->id_card) ->where('telphone', $telphone) ->where('id_card', $id_card) ->first(); if ($res) { $vips->id_card = $id_card; $vips->telphone = $telphone; } $vips->name = $name; $vips->age = $age; $vips->sex = $sex; if ($vips->save()) { return redirect('admin/vip/show/' . $id)->with('message', '修改成功'); } else { return redirect('admin/vip/show/' . $id)->with('message', '修改失败'); }
laravel 验证规则之编辑
最新推荐文章于 2024-11-01 17:20:13 发布