【发布时间】:2015-01-08 11:30:06
【问题描述】:
我有下面的代码
$id = 1;
$idz = 3;
$nums = DB::select(DB::raw('select * from chat_user where user_id in (?, ?) and chat_id in (select chat_id from chat_user group by chat_id having count(*) > 1)'), array($id, $idz));
return $nums->count();
这里我有一个名为“user_chat”的表,我想知道我是否通过他们的“user_id”选择了两行,它们是否具有相同的“chat_id”。当我在 phpmyadmin 的 sql 部分测试代码并返回结果时,代码运行良好。
select * from chat_user where user_id in (1, 3) and chat_id in (select chat_id from chat_user group by chat_id having count(*) > 1)
但是当我用 laravel 的风格写它时,我得到了这个错误:
Call to a member function count() on a non-object
任何帮助都会非常棒!
【问题讨论】:
标签: php mysql laravel laravel-4 query-builder