Laravel 多表查询

public function borrowList(Request $request)
    {
        $user_id = JwtAuth::getInstance()->getUid();
        $limit = $request->input('limit', 20);
        $data_list = YunUserBorrowList::select(['status', 'created_at', 'borrow_no', 'allow_no'])
            ->where('user_id', $user_id)->where('data_from', 1);

        $data = YunUserBorrow::where('user_id', $user_id)
            ->where('data_from', 1)
            ->select(['status', 'created_at', 'borrow_no', 'allow_no'])
            ->union($data_list)
            ->orderby('created_at', 'desc')
            ->paginate($limit)->toArray();

        if (isset($data['data'])) {
            foreach ($data['data'] as $key => $val) {
                $data['data'][$key]['status'] = YunUserBorrow::status($val['status']);
            }
        }

        return Helper::jsonSuccessData($data);
    }
posted @ 2020-12-26 10:06  心之所依  阅读(885)  评论(0编辑  收藏  举报