Home  >  Article  >  Backend Development  >  laravel框架的orderBy问题

laravel框架的orderBy问题

WBOY
WBOYOriginal
2016-06-23 13:24:151546browse

laravel的 orderBy('a','desc'),我如果还想在a一样的情况下,同时根据b降序排序要怎么写


回复讨论(解决方案)

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'])->...

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'])->...

非常感谢,结贴给分!


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'])->...

非常感谢,结贴给分! 第二种方式貌似不行strtolower() expects parameter 1 to be string, array given,只能用第一种了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn