$book = UserModel::where('title','=',$params['title']) ->findOrEmpty(); if (!$book->isEmpty()){ return json([ 'errorCode'=>'10001', 'msg'=>'该图书已存在,请重新添加!', ]); } //添加图书 $result=(new UserModel())->save($params); return json([ 'errorCode'=>'0', 'msg'=>'创建成功', 'result'=>$result ]); 删除
public function dele($id){ $result=UserModel::destroy($id); if($result){ return '删除成功'; } } 修改 public function upda($id){ $data=UserModel::where('id',$id)->select(); if($data){ return View::fetch('show/upda',compact('data')); } } public function update($id){ $data=input(); $res=UserModel::update($data); if($res){ return '修改成功'; } } 状态修改 public function status(Request $request){ $id=$request['id']; $status=$request['status']; if($status==1){ $name['status']=0; }else{ $name['status']=1; } $uname=UserModel::where('id',$id)->update($name); if($uname){ return redirect('list'); }
}