laravel框架的orderBy问题

WBOY
Release: 2016-06-23 13:24:15
Original
1585 people have browsed it

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


回复讨论(解决方案)

orderBy 方法(Builder.php)被写作

	public function orderBy($column, $direction = 'asc')	{		$this->orders[] = compact('column', 'direction');		return $this;	}
Copy after login
Copy after login
Copy after login

所以可以这样写
...->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;	}
Copy after login
Copy after login
Copy after login

所以可以这样写
...->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;	}
Copy after login
Copy after login
Copy after login

所以可以这样写
...->orderBy('a','desc')->orderBy('b','desc')->...
这样写应该也可以
...->orderBy(['a', 'b'], ['desc', 'desc'])->...

非常感谢,结贴给分! 第二种方式貌似不行strtolower() expects parameter 1 to be string, array given,只能用第一种了。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template