laravel框架的orderBy问题

namelesswei 2015-10-21 03:59:08
laravel的 orderBy('a','desc'),我如果还想在a一样的情况下,同时根据b降序排序要怎么写
...全文
1694 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
namelesswei 2015-10-21
  • 打赏
  • 举报
回复
引用 2 楼 namelesswei 的回复:
[quote=引用 1 楼 xuzuning 的回复:] orderBy 方法(Builder.php)被写作
	public function orderBy($column, $direction = 'asc')
	{
		$this->orders[] = compact('column', 'direction');
		return $this;
	}
所以可以这样写 ...->orderBy('a','desc')->orderBy('b','desc')->... 这样写应该也可以 ...->orderBy(['a', 'b'], ['desc', 'desc'])->...
非常感谢,结贴给分![/quote]第二种方式貌似不行strtolower() expects parameter 1 to be string, array given,只能用第一种了。
namelesswei 2015-10-21
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
orderBy 方法(Builder.php)被写作
	public function orderBy($column, $direction = 'asc')
	{
		$this->orders[] = compact('column', 'direction');
		return $this;
	}
所以可以这样写 ...->orderBy('a','desc')->orderBy('b','desc')->... 这样写应该也可以 ...->orderBy(['a', 'b'], ['desc', 'desc'])->...
非常感谢,结贴给分!
xuzuning 2015-10-21
  • 打赏
  • 举报
回复
orderBy 方法(Builder.php)被写作
	public function orderBy($column, $direction = 'asc')
	{
		$this->orders[] = compact('column', 'direction');
		return $this;
	}
所以可以这样写 ...->orderBy('a','desc')->orderBy('b','desc')->... 这样写应该也可以 ...->orderBy(['a', 'b'], ['desc', 'desc'])->...

4,251

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧