//以下File是model
//查找所有数据(三种)
$data=File::orderby('created_at','desc')->get();//按创建时间顺序
$data=File::where('id','>','0')->get();
$data=File::all();
//查找一条(三种)
$data=File::where('id','1')->first();//1维
$data=File::where('id','1')->get();//2维
$data=File::findOrFail(1);//1为id
//多条件查询
$data=File::where('id','1')->where('name','haha')->first();//1维
$data=File::where('id','1')->where('name','haha')->get();//2维
//添加(两种)
$a=new File();$a->字段="值";$a->save();
File::create(['字段'=>"值",'字段'=>"值"]);
//删除(两种)
先写查找一条语句+$data->delete();
$data=File::where('id','1')->delete();
//修改(三种)
先写查找一条语句+$data->字段="值"+$data->save();
先写查找一条语句+File::update(['字段'=>"值",'字段'=>"值"]);
$data=File::where('id','1')->update(['字段'=>"值",'字段'=>"值"]);
laravel基本增删改查语句
最新推荐文章于 2022-07-01 09:45:00 发布