一、查询

$map = [];
$map[] = ['u.store_id','=',0];
$map[] = ['u.reg_time','<',time()];
$map[] = ['u.user_rank','in',[0,9]]; DB::table('user_bonus as ub')
->select('b.type_name','b.discounts','b.discounts_val','b.use_end_time','b.expire_days','ub.status')
->leftJoin('bonus as b','b.type_id','=','ub.type_id')
->where($map)
->groupBy('status')
->offset(10)
->limit(20)
->orderBy('id','desc')
->get(); //从数据库表中获取一行数据,就使用 first 方法
$user = DB::table('users')->where('name', 'John')->first(); //从记录中取出单个值
$email = DB::table('users')->where('name', 'John')->value('email'); //要获取包含单个字段值的集合,可以使用 pluck 方法。
$titles = DB::table('roles')->pluck('title'); //返回的集合中指定字段的自定义键值
$roles = DB::table('roles')->pluck('title', 'name'); //获取记录数
$users = DB::table('users')->count(); //原生sql查询
$users = DB::select('select * from users where active = ?', [1]);

二、插入

//插入一条
DB::table('users')->insert(
['email' => 'john@example.com', 'votes' => 0]
);
//插入多条
DB::table('users')->insert([
['email' => 'taylor@example.com', 'votes' => 0],
['email' => 'dayle@example.com', 'votes' => 0]
]); 若数据表存在自增的 ID,则可以使用 insertGetId 方法来插入记录然后获取其 ID:
$id = DB::table('users')->insertGetId(
['email' => 'john@example.com', 'votes' => 0]
); //原生sql插入
DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);

三、更新

//更新
DB::table('users')
->where('id', 1)
->update(['votes' => 1]); //原生sql更新
$affected = DB::update('update users set votes = 100 where name = ?', ['John']);

四、删除

DB::table('users')->where('votes', '>', 100)->delete();

//原生sql删除
$deleted = DB::delete('delete from users');

五、

//判断请求类型
$request->ajax();
$request->isMethod('GET');
$request->isMethod('POST'); //接受参数
$request->input('name','')

六、SESSION

//设置session值
session()->put('key','value'); Session::put('key','value'); //把数组放到Session
Session::push('student','gao');
Session::push('student','cong'); //获取session值
session()->get('key'); Session::get('key'); Session::get('student'); //取出所有值
Session::all(); //判断session某个值是否存在
Session::has('student'); //删除session的某个值
Sessino:forget('student');

七、返回值、重定向

//返回json数据
return response()->json(); //重定向
return redirect()->with('message','消息');
return redirect()->action('UserController@login')->with('message','消息');
return redirect()->route('路由别名')->with('message','消息');
return redirect()->back();

 

最新文章

  1. Advanced REST client的使用说明
  2. Oracle 通过sql profile为sql语句加hint
  3. 火星A+B(字符串整形转化,进制)
  4. HDU 1203 I NEED A OFFER!(dp)
  5. Longest Palindromic Substring2015年6月20日
  6. RxJava(11-线程调度Scheduler)
  7. 使用HTML5抓取 Audio &amp; Video
  8. [RESTful] RESTful是什么,为什么要使用它
  9. GNum试用体验
  10. Jmeter如何提取响应头部的JSESSIONID
  11. 复习ing
  12. django模板语言的注释
  13. Java含有Date的对象序列化网络传输
  14. UVa 10763 Foreign Exchange(map)
  15. 2018.08.17 洛谷[POI2010]GRA-The Minima Game(线性dp)
  16. ubuntu16.04搭建hadoop集群环境
  17. UOJ #122 【NOI2013】 树的计数
  18. 开博缘由 , 可点下看看 http://www.cnblogs.com/jshare
  19. kendalltau肯德尔和谐系数
  20. JS中的“==”与强制类型转换

热门文章

  1. 使用 VSCode 在 Mac 上配置 C/C++ 调试环境
  2. Python基础篇_实例练习(二)
  3. python-参考书
  4. AspNetCore3.1_Secutiry源码解析_5_Authentication_OAuth
  5. volatile 手摸手带你解析
  6. 在MacOS上利用docker构建buildroot
  7. Python-String字符串操作
  8. Spinner 用法
  9. angualrjs 总结 随记(一)
  10. 第十五周java实验作业