Attach action error in RelationManager

I am getting below error during Select search while performing Attach action in header of Relationship manager.
Call to undefined method App\Models\Setting\BusinessCategory::businessCategories()
Call to undefined method App\Models\Setting\BusinessCategory::businessCategories()
I have BusinessCategory model with N:N relationship with itself. My model has parents() and children() methods. Currently it is only two level. And I using using simple Attach action in the Header.
4 Replies
toeknee
toeknee3mo ago
It's looking for the relationship businessCategories on the Model BusinessCategory
Dennis Koch
Dennis Koch3mo ago
You probably need to define $inverseRelationship property when you have non-common relationship names
Pritbor
Pritbor3mo ago
Agree. Hi @Dennis Koch . i tried
public function scopeWithNoChildren(Builder $query): Builder
{
return $query->whereDoesntHave('children');
}

// Method to get categories with no children
public static function businessCategories(): Builder
{
return self::withNoChildren();
}
public function scopeWithNoChildren(Builder $query): Builder
{
return $query->whereDoesntHave('children');
}

// Method to get categories with no children
public static function businessCategories(): Builder
{
return self::withNoChildren();
}
But i still get error Call to undefined method Illuminate\Database\Eloquent\Builder::getRelated(). I am writing custom Attach action now.
Dennis Koch
Dennis Koch3mo ago
What's self in this context? Because this is not a relationship 🤔
Want results from more Discord servers?
Add your server