# 查询构造器 在模型中仍然可以调用数据库的链式操作和查询方法,可以充分利用数据库的查询构造器的优势。 ## 排序 order ```php $data = User::where('status',1)->order('id desc')->select(); $data = User::where('status',1)->order('id asc')->select(); ``` 转化为 SQL 分别为 ```sql SELECT * FROM `zh_user` WHERE `status` = 1 ORDER BY id desc SELECT * FROM `zh_user` WHERE `status` = 1 ORDER BY id asc ``` ## 限制 limit ```php $data = User::where('status',1)->limit(2)->select(); $data = User::where('status',1)->limit(2, 5)->select(); ``` 转化为 SQL 分别为 ```sql SELECT * FROM `zh_user` WHERE `status` = 1 LIMIT 2 SELECT * FROM `zh_user` WHERE `status` = 1 LIMIT 2, 4 ``` 利用 limit 语句可以很容易的实现分页操作