Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 5.3)_Php_Sql_Laravel_Eloquent_Laravel 5.3 - Fatal编程技术网

Php 通过第三种关系对分页进行排序(Laravel 5.3)

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

我的桌子是这样的:

图像

身份证

用户id

路径

用户

身份证

名字

密码

帖子

身份证

内容

用户id

我想把所有的帖子都编页码。我想相关的用户有一个图像的帖子去第一,然后休息。目前,我有这个,但它不是我想要的:

$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);

你目前的成绩有什么问题?我想您可能想尝试外部联接。请描述该问题