Laravel Eloquent:嵌套关系可保存数据

时间:2018-08-20 01:33:16

标签: laravel eloquent nested relationships

我想在具有https://regex101.com/r/FZTp5T/5 mid的令牌上保存数据

tid对商家mid的引用

id对终端tid的引用

id

商人hasMany(终端) 终端hasMany(Token)

class Merchant {
   public function terminal() {
        return $this->hasMany('App\Models\Terminal', 'tid');
    }

    public function token()
    {
        return $this->hasMany('App\Models\Token', 'mid');
    }
}

class Terminal {
       public function merchant() {
        return $this->belongsTo(Merchant::class);
    }

    public function token()
    {
        return $this->hasMany('App\Models\Token', 'tid');
    }
}

class Token {
    public function terminal()
    {
        return $this->belongsTo(Terminal::class);
    }

    public function merchant()
    {
        return $this->belongsTo(Merchant::class);
    }
}

引发错误: Merchant id mid Terminal id tid Token id mid tid token $merchant_info->terminal->token->save(new Token($data));

0 个答案:

没有答案