laravel6 使用Uniaon联合查询orm

 

 

$table1 = UserTestDynamicVote::query()
            ->where('user_id','=',$user_id)
            ->where('status','=',1)
            ->select(['id','dynamic_id',\DB::raw("'' as content"),\DB::raw("'1' as type_num"),'updated_at']);

        $commentModel = UserTestComment::query()
            ->where('to_user_id','=',$user_id)
            ->where('is_vote','=',1)
            ->where('status','=',1)
            ->select(['id','comment_id as dynamic_id','content',\DB::raw("'2' as type_num"),'updated_at']);

        $userVoteModel = UserTestDynamicVote::query()
            ->select(['id','dynamic_id',\DB::raw("'' as content"),\DB::raw("'3' as type_num"),'updated_at']);

        $resData = $table1->union($commentModel)
            ->union($userVoteModel)
            ->orderBy('updated_at','desc')
            ->paginate(10);

 

posted @ 2020-12-10 17:34  林间有风-邓  阅读(312)  评论(0编辑  收藏  举报