laravel hasOne hasMany模型关联查询

hasOne

    public function findByRandAll()
    {
        return $this->where("status", '<>', '0')
            ->inRandomOrder()
            ->with(['userinfo:uid,nickname,avatar'])
            ->select(['winner_uid', 'money'])
            ->limit(20)
            ->get()->toArray();
    }

    public function userinfo()
    {
        //uid为McMembersModel表的外键id     winner_uid为调用表的挖建id
        return $this->hasOne("App\Http\Model\McMembersModel", "uid", "winner_uid");
    }

猜你喜欢

转载自blog.csdn.net/helloworld_dream/article/details/86545283
今日推荐