如何通过嵌套关系Laravel Eloquent来订购集合

时间:2014-11-17 12:01:58

标签: php mysql database laravel eloquent

即使在阅读了docs&例子。 我想按价格订购。 price属性嵌套在需要由用户ID和服务类型ID访问的关系中。 这是表格之间的关系,其中有我需要用于排序的标准:

修改 感谢@jarek:@)

$users_available = $users_available->join('stypes_4_user', function($join)use($stype)
                              {
                                $join->on('user_id', '=', 'users.id')
                                      ->where('service_type_id', '=', $stype);
                              })
                            ->orderBy('price', 'desc')->get();

编辑2 如果您在加入后使用->select('*')并且无法访问模型的方法后最终陷入困境,请确保您正在调用'yourtablename.*'而不仅仅是'*'。在这里阅读更多: http://jpcamara.com/selecting-carefully-laravel-joins/

0 个答案:

没有答案