首页 > 代码库 > Laravel增删改查语句总结
Laravel增删改查语句总结
<?php Class Que { /* * 查询: */ public function index() { $users = User::query()->paginate(20); return view(‘admin.user.index‘, [‘list‘ => $users]); $list = Category::get(); return view(‘admin.product.category.index‘, [‘list‘ => $list]); } /* *保存: */ public function store1() { $input = Input::except(‘_token‘); $rules = [ ‘cate_name‘ => ‘required‘, ]; $message = [ ‘cate_name.required‘ => ‘分类名称不能为空!‘, ]; $validator = Validator::make($input, $rules, $message); if ($validator->passes()) { $re = Category::create($input); if ($re) { return redirect(‘admin/category‘); } else { return back()->with(‘errors‘, ‘数据填充失败,请稍后重试!‘); } } else { return back()->withErrors($validator); } } public function store2(Request $request) { $input = $request->except(‘_token‘); $rules = [ ‘true_name‘ => ‘required‘, ‘mob_phone‘ => ‘required|regex:/^1\d{10}$/‘ ]; $message = [ ‘true_name.required‘ => ‘姓名不能为空‘, ‘mob_phone.required‘ => ‘电话号码不能为空‘, ‘mob_phone.regex‘ => ‘电话号码不符合要求‘ ]; $validator = Validator::make($input, $rules, $message); if ($validator->passes()) { $re = Address::create($input); if ($re) { return redirect(‘member/address‘); } else { return back()->with(‘errors‘, ‘地址提交失败‘); } } else { return back()->withErrors($validator); } return redirect(‘Member\AddressController@index‘); } /* * delete */ public function destroy($id) { Address::where(‘address_id‘, ‘=‘, $id)->delete(); return redirect(‘member/address‘); } }
Laravel增删改查语句总结
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。