Call to undefined method Illuminate\Database\Query\Builder::associate()

后端 未结 4 936
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 11:29

Reference: How can I update an existing Eloquent relationship in Laravel 4?

$userinfo = \\Userinfo::find($id);
\\User::find($id)->userinfo()->associate         


        
4条回答
  •  温柔的废话
    2021-01-01 12:23

    Change hasOne to belongsTo. It will look like:

    class User extends Eloquent {
    
        public function userinfo()
        {
            return $this->belongsTo('Userinfo');
        }
    }
    
    class Userinfo extends Eloquent {
    
        public function user() {
            return $this->belongsTo('User');
        }
    }
    

提交回复
热议问题