F
Filament17mo ago
caweren

Missing route parameter when editing resource

Hi all! Relatively new to Filament, coming from Nova. I have a Tenant resource that spits out an error message when I try to edit them (Note, edit. Creation/deletion works fine). It has 2 inputs, a name (string) and a license_id (select, integer, refers to id on licenses table) When ever I try to change anything in the resource, be it name or license, then it errors out with the following error message:
Missing required parameter for [Route: filament.resources.tenants.edit] [URI: admin/tenants/{record}/edit] [Missing parameter: record].
Missing required parameter for [Route: filament.resources.tenants.edit] [URI: admin/tenants/{record}/edit] [Missing parameter: record].
Looking through the trace, it seems to come from Livewires SupportBrowserHistory feature> I've Googled around, but all the answers seems to be some of the more "obvious" once (like wrong parameter name in redirect's etc.). I haven't changed anything in the default Filament routing, and all other resources works correctly, it's only this one. The primary key type of Tenant is a string, and not and integer - I don't know if this is relevant, but it's the only differing factor I can find. I'm happy to supply any code you might want to check through, please let me know.
13 Replies
Vp
Vp17mo ago
Is your edit page is custom? if yes, then you probably need to put mount($record). and yes, code will be helpful
caweren
cawerenOP17mo ago
the edit page is the default one that gets generated with php artisan make:filament-resource TenantResource --generate:
<?php

namespace App\Filament\Resources\TenantResource\Pages;

use App\Filament\Resources\TenantResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;

class EditTenant extends EditRecord
{
protected static string $resource = TenantResource::class;

protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
<?php

namespace App\Filament\Resources\TenantResource\Pages;

use App\Filament\Resources\TenantResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;

class EditTenant extends EditRecord
{
protected static string $resource = TenantResource::class;

protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
Vp
Vp17mo ago
Can you share TenantResource page, not edit
caweren
cawerenOP17mo ago
Sure, here:
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\TenantResource\Pages;
use App\Models\Tenant;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;

class TenantResource extends Resource
{
protected static ?string $model = Tenant::class;

protected static ?string $navigationIcon = 'heroicon-o-users';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('id')
->required()
->maxLength(255),
Forms\Components\Select::make('License')
->relationship('license', 'name')
->default('1')
->required()
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('license.name'),
Tables\Columns\TextColumn::make('Seats used')
->getStateUsing(function (Tenant $record) {
return "{$record->license->tenants->count()} / {$record->license->seats}";
})
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListTenants::route('/'),
'create' => Pages\CreateTenant::route('/create'),
'edit' => Pages\EditTenant::route('/{record}/edit'),
];
}
}
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\TenantResource\Pages;
use App\Models\Tenant;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;

class TenantResource extends Resource
{
protected static ?string $model = Tenant::class;

protected static ?string $navigationIcon = 'heroicon-o-users';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('id')
->required()
->maxLength(255),
Forms\Components\Select::make('License')
->relationship('license', 'name')
->default('1')
->required()
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('license.name'),
Tables\Columns\TextColumn::make('Seats used')
->getStateUsing(function (Tenant $record) {
return "{$record->license->tenants->count()} / {$record->license->seats}";
})
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListTenants::route('/'),
'create' => Pages\CreateTenant::route('/create'),
'edit' => Pages\EditTenant::route('/{record}/edit'),
];
}
}
Vp
Vp17mo ago
It's weird, I also used "UUID" and I didn't have any error.. Sorry to hype up but I don't have any idea now.. at last which version you're using?
caweren
cawerenOP17mo ago
2.17.50 Thanks for trying though 🙂
Vp
Vp17mo ago
It may not help but did you put public $incrementing = false; and protected $keyType = 'string'; in your model?
caweren
cawerenOP17mo ago
I had not, no. I just added both, didn't change anything 😦
Vp
Vp17mo ago
Hi, I have check and yet I don't have a problem, I'll show you what I did then you can have ref from there in Database
$table->string('tenant')->primary()->unique();
$table->string('license');
$table->string('tenant')->primary()->unique();
$table->string('license');
in model
protected $primaryKey = 'tenant';

protected $keyType = 'string';

public $incrementing = false;
protected $primaryKey = 'tenant';

protected $keyType = 'string';

public $incrementing = false;
Form and Table, I used your code, but I didn't create relationship..
Vp
Vp17mo ago
Here is video of what I mention above
caweren
cawerenOP17mo ago
Sorry about the delay, had lunch 🙂 So, testing a little further - if i add id to $fillable on the Tenant model, the error goes away and i get the notification that the settings has been saved! However, the changes are not saved. Also, looking through the request sent to Livewire when i click "save changed", i can see license_id and license. license_id is unchanged from the database value, while license has the new, updated value (this ofcourse won't get saved, since license is not a column in my database). Is it possible, on a select with relationship, to manually put in the column name?
Vp
Vp17mo ago
Forms\Components\Select::make('license_id') ?
caweren
cawerenOP17mo ago
Yeah, that's what i ended up with. The missing route parameter was due to id not being in the $fillable array, so it got stripped from the request before livewire tried to solve the route. However, the model is not getting saved now - I'll make a new thread for this. Thank your for helping out, marking as solved.
Want results from more Discord servers?
Add your server