Is there a more elegant way to change breadcrump url in nested resource?

I have built this, but I dont like the solution.
public function getBreadcrumbs(): array
{
$newBreadcrumbs = [];

foreach (parent::getBreadcrumbs() as $key => $value) {
if (str_contains($key, 'relation=goalEvaluations')) {
$newKey = str_replace('?relation=goalEvaluations', '/zielauswertungen', $key);
$newBreadcrumbs[$newKey] = 'Zielauswertung';
} else {
$newBreadcrumbs[$key] = $value;
}
}

return $newBreadcrumbs;
}
public function getBreadcrumbs(): array
{
$newBreadcrumbs = [];

foreach (parent::getBreadcrumbs() as $key => $value) {
if (str_contains($key, 'relation=goalEvaluations')) {
$newKey = str_replace('?relation=goalEvaluations', '/zielauswertungen', $key);
$newBreadcrumbs[$newKey] = 'Zielauswertung';
} else {
$newBreadcrumbs[$key] = $value;
}
}

return $newBreadcrumbs;
}
2 Replies
hlonish
hlonish2mo ago
public function getBreadcrumbs(): array { return collect(parent::getBreadcrumbs()) ->mapWithKeys(fn ($value, $key) => str_contains($key, 'relation=goalEvaluations') ? [str_replace('?relation=goalEvaluations', '/zielauswertungen', $key) => 'Zielauswertung'] : [$key => $value] ) ->all(); }
igorclauss
igorclaussOP2mo ago
Thank you very much! That is indeed better. I was wondering if there was a 'filament way' of doing this.

Did you find this page helpful?