Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在laravel中搜索和排序?_Php_Laravel - Fatal编程技术网

Php 在laravel中搜索和排序?

Php 在laravel中搜索和排序?,php,laravel,Php,Laravel,在拉威尔,我知道你能做到 $users = Post::where('hide', '=', 0)->take(40)->get(); 获取hide=0且 $users = Post::orderBy('created_at', 'DESC')->take(20)->get(); 要对它们进行排序,但如果我想同时执行这两项操作,该怎么办?您应该可以执行 $users = Post::where('hide', '=', 0)->orderBy('created_

在拉威尔,我知道你能做到

$users = Post::where('hide', '=', 0)->take(40)->get();
获取hide=0且

$users = Post::orderBy('created_at', 'DESC')->take(20)->get();

要对它们进行排序,但如果我想同时执行这两项操作,该怎么办?

您应该可以执行

$users = Post::where('hide', '=', 0)->orderBy('created_at', 'desc')->take(20)->get();

你可以在
where
之后继续链接方法,我知道了,我以为::是->以外的其他类型的东西,但是我现在理解了链接,谢谢!