Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 2 years ago.
0

Try this:

public function masterOf (){
    return $this->belongsToMany('Fighter', 'fighter_fighter', 'fighter_id', 'fighter_id_mestre');
}
public function trainedBy(){
    return $this->belongsToMany('Fighter', 'fighter_fighter', 'fighter_id_mestre', 'fighter_id');
}

Anyway, maybe is better to rename table with something like "fighter_training" ;)

Last updated 2 years ago.
0

NeiPCs said:

Try this:

public function masterOf (){
   return $this->belongsToMany('Fighter', 'fighter_fighter', 'fighter_id', 'fighter_id_mestre');
}
public function trainedBy(){
   return $this->belongsToMany('Fighter', 'fighter_fighter', 'fighter_id_mestre', 'fighter_id');
}

Anyway, maybe is better to rename table with something like "fighter_training" ;)

Thank you so much, man. I was facing the same problem and this solved it. I already knew how to override the fields but was strugling on how to determine which would be the pivot in this kind of many-to-many self-relation using the ORM.

Cheers.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

souljacker souljacker Joined 11 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.