Laravel增删改查语句总结
Posted 记录
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\[email protected]‘); } /* * delete */ public function destroy($id) { Address::where(‘address_id‘, ‘=‘, $id)->delete(); return redirect(‘member/address‘); } }
以上是关于Laravel增删改查语句总结的主要内容,如果未能解决你的问题,请参考以下文章