【发布时间】:2016-11-15 13:21:52
【问题描述】:
我在更复杂的查询中遇到了 orderBy 的问题。
我想从指定的俱乐部中获取 10 个有序用户(以俱乐部为中心)并隐藏一些列。
所以我有一个雄辩的查询,这几乎对我有用。问题在于通过某些变量(级别或 exp - 尚不知道)对用户排序。
我的查询(工作 - 没有排序):
$users = Club::find($club_id)->users->each(function($row) {
$row->setHidden(['history', 'books', 'reviews', 'exp', 'erudion_id', 'phone', 'bio', 'active', 'book_transfer_type', 'email', 'password', 'remember_token', 'created_at', 'updated_at', 'active_club', 'facebook_id', 'password_token', 'points', 'password_status', 'pivot']);
})->take(10);
return $users;
我的一个试验(使用 OrderBy):
//
// $users = Club::find($club_id)->with(['users' => function ($q) {
//
// $q->orderBy('id');
//
// }])->each(function($row) {
//
// $row->setHidden(['history', 'books', 'reviews', 'exp', 'erudion_id', 'phone', 'bio', 'active', 'book_transfer_type', 'email', 'password', 'remember_token', 'created_at', 'updated_at', 'active_club', 'facebook_id', 'password_token', 'points', 'password_status', 'pivot']);
//
// });
//
// return $users;
错误:
响应内容必须是实现__toString()的字符串或对象,“boolean”给定。
我在我的模型中附加了属性。这个属性不能通过不包含在select中来取消选中,所以基本上都是选中的。
我想创建一个雄辩的查询,它将属性限制在少数,这是我感兴趣的。
【问题讨论】: