Skip to content

Commit

Permalink
fix: global search for root resources
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <mail@lukasfrey.cz>
  • Loading branch information
lukas-frey committed Nov 17, 2023
1 parent d3e8da6 commit 68a2c81
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/Resources/NestedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Guava\Filament\NestedResources\Concerns\HasBreadcrumbTitleAttribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;

abstract class NestedResource extends Resource
Expand Down Expand Up @@ -126,17 +127,31 @@ public static function getBreadcrumbs(Page $page, Model $record = null): array
public static function getGlobalSearchResultUrl(Model $record): ?string
{
if (static::hasPage('edit') && static::canEdit($record)) {
return static::getUrl('edit', [
...static::getAncestor()->getNormalizedRouteParameters($record),
'record' => $record,
]);
return static::getUrl(
'edit',
collect([
'record' => $record->id,
])
->when(
$ancestor = static::getAncestor(),
fn (Collection $collection) => $collection->mergeRecursive(...$ancestor->getNormalizedRouteParameters($record))
)
->toArray()
);
}

if (static::hasPage('view') && static::canView($record)) {
return static::getUrl('view', [
...static::getAncestor()->getNormalizedRouteParameters($record),
'record' => $record,
]);
return static::getUrl(
'view',
collect([
'record' => $record->id,
])
->when(
$ancestor = static::getAncestor(),
fn (Collection $collection) => $collection->merge($ancestor->getNormalizedRouteParameters($record))
)
->toArray()
);
}

return parent::getGlobalSearchResultUrl($record);
Expand Down

0 comments on commit 68a2c81

Please sign in to comment.