Issue with RelationManager in one direction when I want to attach an element

Hi , I'm encountering the following issue with 2 models on which I have deployed a Many-to-Many relationship . So I have created two RelationManagers that I 'm using back and forth on my 2 resources defined and it seems to work but within one of my resources when I'm using the RelationManager associated and that I want to attach an existing element in my table . I got the error message -> BadMethodCallException: "Call to undefined method App\Models\ ...". I have doublecheck many time my relation in both of my models but the relation is well present . In the same error page for the explanation about bad method call , it seems that it suggest me the correct relationship If I'm defining the same without the RelationManager for this resource but just using a regular expression select within the form with the relationship and so on then it is working fine . In that case my pivot table is well updated . I don't know why it is not working because I'm using the same relation but back and forth My Model 1 relation is defined as follow:
public function endusers()
{
return $this->belongsToMany(CucmEndUser::class, 'cucm_end_user_line_group', 'line_group_id', 'cucm_end_user_id')
->withPivot('member_uuid', 'line_selection_order', 'is_active')
->withTimestamps();
}
public function endusers()
{
return $this->belongsToMany(CucmEndUser::class, 'cucm_end_user_line_group', 'line_group_id', 'cucm_end_user_id')
->withPivot('member_uuid', 'line_selection_order', 'is_active')
->withTimestamps();
}
And I think that this one if working well because I can acess my users defined in this model The other Model relation is defined as :
public function linegroups()
{
return $this->belongsToMany(LineGroup::class, 'cucm_end_user_line_group', 'cucm_end_user_id', 'line_group_id')
->withPivot('member_uuid', 'line_selection_order', 'is_active')
->withTimestamps();
}
public function linegroups()
{
return $this->belongsToMany(LineGroup::class, 'cucm_end_user_line_group', 'cucm_end_user_id', 'line_group_id')
->withPivot('member_uuid', 'line_selection_order', 'is_active')
->withTimestamps();
}
` It is just with the attach action on this relation that it is not working . The DetachAction is working well As newbie , not sure what I'm doing wrong . Many thanks
1 Reply
oks_voice123
oks_voice123OP7mo ago
I found the issue , I need to define the following implementation
protected static ?string $inverseRelationship = 'endusers';
protected static ?string $inverseRelationship = 'endusers';
` So it is the reverse name of my relation But I don't get why I need to put it in one RelationManager class and not the other Anyone for an explanation ? thank you
Want results from more Discord servers?
Add your server