Php 通过第三种关系对分页进行排序(Laravel 5.3)
我的桌子是这样的: 图像 身份证 用户id 路径 用户 身份证 名字 密码 帖子 身份证 内容 用户id 我想把所有的帖子都编页码。我想相关的用户有一个图像的帖子去第一,然后休息。目前,我有这个,但它不是我想要的:Php 通过第三种关系对分页进行排序(Laravel 5.3),php,sql,laravel,eloquent,laravel-5.3,Php,Sql,Laravel,Eloquent,Laravel 5.3,我的桌子是这样的: 图像 身份证 用户id 路径 用户 身份证 名字 密码 帖子 身份证 内容 用户id 我想把所有的帖子都编页码。我想相关的用户有一个图像的帖子去第一,然后休息。目前,我有这个,但它不是我想要的: $posts = Post::where('subject_id', '=', $subject->id) ->approved() ->select(['*', DB::raw('(SELECT count(images.id) F
$posts = Post::where('subject_id', '=', $subject->id)
->approved()
->select(['*', DB::raw('(SELECT count(images.id) FROM images INNER JOIN users ON images.user_id = users.id WHERE posts.user_id = users.id) as count_images')])
->orderBy('count_images', 'desc')
->orderBy('created_at', 'desc')
->paginate(18);
你目前的成绩有什么问题?我想您可能想尝试外部联接。请描述该问题