diff --git a/README.md b/README.md index d4b4d3a..4a28711 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/howdu/filament-record-switcher/fix-php-code-styling.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/howdu/filament-record-switcher/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/howdu/filament-record-switcher.svg?style=flat-square)](https://packagist.org/packages/howdu/filament-record-switcher) -Subtly convert the page title into a dropdown navigation that's displayed on click. +Subtly convert the page title into a dropdown navigation that's displayed on click. -It works similar to Filament's global search but only show results for the current resource. +It works similar to Filament's global search but only shows results for the current resource. ![preview](https://github.com/howdu/filament-record-switcher/assets/533658/f0c62589-bd5f-4463-bf93-124b1c37955b) @@ -45,7 +45,7 @@ class AdminPanelProvider extends PanelProvider } ``` 2. Add the `HasRecordSwitcher` trait to each of your edit record Page. -E.g `app/Filament/Resources/Category/EditCategory.php` +E.g `app/Filament/Resources/Category/Pages/EditCategory.php` ```php use Howdu\FilamentRecordSwitcher\Filament\Concerns\HasRecordSwitcher; @@ -54,6 +54,10 @@ class EditCategory extends EditRecord use HasRecordSwitcher; } ``` + +Note: this trail will overwrite the `getHeading()` method if you've overwritten it in your Page you need to +overwrite `getRecordTitle()` instead. + 3. Publish plugin assets. ```bash php artisan filament:assets diff --git a/resources/views/components/record-switcher.blade.php b/resources/views/components/record-switcher.blade.php index 4894e3a..900257c 100644 --- a/resources/views/components/record-switcher.blade.php +++ b/resources/views/components/record-switcher.blade.php @@ -19,7 +19,7 @@ searchPrompt: '{{ __('filament-forms::components.select.search_prompt') }}', searchingMessage: '{{ __('filament-forms::components.select.searching_message') }}', state: @js($value), - updateSelected: async (value) => await $wire.updateRecordSwitcher(value), + updateSelected: (value) => window.location.href = value, })" wire:ignore x-on:keydown.esc="select.dropdown.isActive && $event.stopPropagation()" diff --git a/src/Filament/Concerns/HasRecordSwitcher.php b/src/Filament/Concerns/HasRecordSwitcher.php index 20634bf..0a7dbe2 100644 --- a/src/Filament/Concerns/HasRecordSwitcher.php +++ b/src/Filament/Concerns/HasRecordSwitcher.php @@ -91,7 +91,7 @@ protected static function applyRecordSwitcherAttributeConstraint(Builder $query, $query->when( str($searchAttribute)->contains('.') - && ! str($searchAttribute)->contains('`'), + && ! str($searchAttribute)->contains('`'), function (Builder $query) use ($databaseConnection, $isForcedCaseInsensitive, $searchAttribute, $search, $whereClause): Builder { return $query->{"{$whereClause}Relation"}( (string) str($searchAttribute)->beforeLast('.'), @@ -113,17 +113,10 @@ function (Builder $query) use ($databaseConnection, $isForcedCaseInsensitive, $s return $query; } - public function updateRecordSwitcher($value) - { - $url = self::getResource()::getUrl('edit', ['record' => $value]); - - $this->redirect($url); - } - protected function recordSwitcherItem(Model $model): array { $item = [ - 'value' => $model->getKey(), + 'value' => self::getResource()::getUrl('edit', ['record' => $model->getRouteKey()]), 'label' => $this->recordSwitcherItemLabel($model), ];