Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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使用GroupBy并获取最新条目_Php_Laravel_Laravel 4 - Fatal编程技术网

Php Laravel使用GroupBy并获取最新条目

Php Laravel使用GroupBy并获取最新条目,php,laravel,laravel-4,Php,Laravel,Laravel 4,我目前正在使用groupBy('conv_id')将名为messages的表中的行分组到对话中 现在,所有返回的结果都将是唯一的conv_id,尽管唯一行不是最新的,而是创建的第一行 使用orderBy('created_at','desc')没有什么作用,我如何查询最新的行 我现在使用的查询: $this->orderBy('created_at', 'desc')->where('receiver', '=', $id)->orWhere('sender', '=', $i

我目前正在使用
groupBy('conv_id')
将名为
messages
的表中的行分组到对话中

现在,所有返回的结果都将是唯一的
conv_id
,尽管唯一行不是最新的,而是创建的第一行

使用
orderBy('created_at','desc')
没有什么作用,我如何查询最新的行

我现在使用的查询:

$this->orderBy('created_at', 'desc')->where('receiver', '=', $id)->orWhere('sender', '=', $id)->groupBy('conv_id')->select('conv_id', 'created_at')->get()->toArray();
该表如下所示:

$this->orderBy('created_at', 'desc')->where('receiver', '=', $id)->orWhere('sender', '=', $id)->groupBy('conv_id')->select('conv_id', 'created_at')->get()->toArray();
ID |发送方|接收方|在|更新|在|创建|在| CONV | ID

我想,您使用的tf

Message::where('receiver', '=', $id)
->orWhere('sender', '=', $id)
->orderBy('created_at', 'desc')
->select('conv_id', 'created_at')->take(1)->get();
然后,这将根据
created\u at
中的
where
子句返回最后一个条目/行