filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.3k stars 2.96k forks source link

Filament and Spatie Laraver custom getRouteKeyName fail #10389

Closed StefanoTesla closed 11 months ago

StefanoTesla commented 11 months ago

Package

filament/filament

Package Version

latest

Laravel Version

latest

Livewire Version

No response

PHP Version

8.2

Problem description

I'm using mcamara/laravel-localization and spatie/laravel-translatable and filamentphp/spatie-laravel-translatable-plugin

To make the models viewing and get the others languages correct slug I need to set the model getRouteKeyName as this:

    public function getRouteKeyName()
    {
        $currentLocale = App()->getLocale();
        return "slug->{$currentLocale}";
    }

but with this trick filament fail: [Missing required parameter for [Route: filament.admin.resources.categorie.edit] [URI: admin/categorie/{record}/edit] [Missing parameter: record].](http://127.0.0.1:8000/admin/categorie#top)

If I change the getRouteKeyName as this:

    public function getRouteKeyName()
    {
        return 'slug';
    }

Filament work, but the entry site not.

I tried to add protected static ?string $recordRouteKeyName = 'id'; (I don't care about slug in filament) but nothing change.

Expected behavior

Filament don't goes in error

Steps to reproduce

Make the same getRouteKeyName like me and tadan

Reproduction repository

https://github.com/icantdoit/

Relevant log output

No response

StefanoTesla commented 11 months ago
  //a lot of use use use

class ProductsResource extends Resource
{
    use Translatable;

   //some variable
    protected static ?string $recordRouteKeyName = 'id';

   //some models
    public static function getPages(): array
    {
        return [
            'index' => Pages\ListCategories::route('/'),
            'create' => Pages\CreateCategories::route('/create'),
            'edit' => Pages\EditCategories::route('/{record:id}/edit'),
        ];
    }

If I my resource I do this, work!

danharrin commented 11 months ago

No reproduction repository. Let me know when you have one and I'll reopen it.