How to show total count of related record on Manage Related Record tab badge ?

Count the related record and show ton the navigation badge like this.
No description
12 Replies
dissto
dissto2mo ago
On a relation manager you could do something like:
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
{
return $ownerRecord->{static::$relationship}->count();
}
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
{
return $ownerRecord->{static::$relationship}->count();
}
🤔
Asmit Nepali
Asmit Nepali2mo ago
But I used
ManageRelatedRecords
ManageRelatedRecords
dissto
dissto2mo ago
My bad, i was assuming that MRR would provide a similar method, but after some short digging, it turns out there is no similar method that would give simple access to the $ownerRecord 🤔 You could maybe do something like:
public static function getNavigationBadge(): ?string
{
return static::getResource()::getModel()::count();
}
public static function getNavigationBadge(): ?string
{
return static::getResource()::getModel()::count();
}
But that is also not what you want, because that would just be the count of records as opposed to the $ownerRecords count. So I don't know at the top of my hat how solve this, but im sure someone else knows 😂 There are methods to get the ownerRecord but those are not static 🤔
Asmit Nepali
Asmit Nepali2mo ago
One solution is like
public static function getNavigationBadge(): ?string
{
return static::getResource()::getModel()::find(request()->route('record'))?->notes->count();
}
public static function getNavigationBadge(): ?string
{
return static::getResource()::getModel()::find(request()->route('record'))?->notes->count();
}
But this is not a good solution Anyone have any Idea about this ?
awcodes
awcodes2mo ago
This works. Why is it a bad solution?
Asmit Nepali
Asmit Nepali2mo ago
The owner record is already there then why should we fetch again. Is there any way to get ownerRecrod, here the getOwnerRecord is not static.
awcodes
awcodes2mo ago
Because the navigation is outside of the the page livewire component.
Asmit Nepali
Asmit Nepali2mo ago
Which one is better to manage relation, MRR or RM ?
awcodes
awcodes2mo ago
IMHO it doesn’t matter. It all gets processed at the same time.
Asmit Nepali
Asmit Nepali2mo ago
I found that the RM have one extra query that's why I'm switching to MRR
awcodes
awcodes2mo ago
Then navigation badge is separate to the the Lw component so they exist independently of each other.
Asmit Nepali
Asmit Nepali2mo ago
Thank You @awcodes
Want results from more Discord servers?
Add your server
More Posts