thinkphp6 + 增删改查 +文件上传

$params = $request->post();  
        $file = $request->file(‘images‘);
        $fileName = \think\facade\Filesystem::disk(‘public‘)
                  ->putFile( ‘/‘, $file);
        $params[‘image‘] = ‘http://tps.com/storage/‘ . $fileName;

        $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‘);
       }
     

    }

thinkphp6 + 增删改查 +文件上传

上一篇:C++ Primer中文版(第5版) pdf 电子书 下载


下一篇:webpack4的简单配置