custom page params

Hi, I'm upgrading an app from v2 to v3. I have a custom page that load and manage a model that does not have a Resource. In v2 the page structure was like this
<?php

namespace App\Filament\Pages;

use App\Models\ProjectStatusPivot;
use Closure;

use Filament\Pages\Actions\Action;
use Filament\Pages\Page;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Route;


class SingleProjectStatus extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.single-project-status.single-project-status';
protected static ?string $slug = 'project-status';


public ProjectStatusPivot $projectStatusPivot;

public function mount() {
$this->projectStatusPivot->loadMissing(['author', 'project']);
}

protected function getActions(): array
{
return [
Action::make('settings')
->label('Settings')
->action('openSettingsModal'),
];
}

public static function getRoutes(): Closure
{
return function () {
$slug = static::getSlug();

Route::get($slug . '/{projectStatusPivot}', static::class)
->middleware(static::getMiddlewares())
->name($slug);
};
}
}
<?php

namespace App\Filament\Pages;

use App\Models\ProjectStatusPivot;
use Closure;

use Filament\Pages\Actions\Action;
use Filament\Pages\Page;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\Route;


class SingleProjectStatus extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.single-project-status.single-project-status';
protected static ?string $slug = 'project-status';


public ProjectStatusPivot $projectStatusPivot;

public function mount() {
$this->projectStatusPivot->loadMissing(['author', 'project']);
}

protected function getActions(): array
{
return [
Action::make('settings')
->label('Settings')
->action('openSettingsModal'),
];
}

public static function getRoutes(): Closure
{
return function () {
$slug = static::getSlug();

Route::get($slug . '/{projectStatusPivot}', static::class)
->middleware(static::getMiddlewares())
->name($slug);
};
}
}
the generated route was /project-status/{projectStatusPivot} Now in v3
public static function getRoutes(): Closure
{
return function () {
$slug = static::getSlug();

Route::get($slug . '/{projectStatusPivot}', static::class)
->middleware(static::getMiddlewares())
->name($slug);
};
}
public static function getRoutes(): Closure
{
return function () {
$slug = static::getSlug();

Route::get($slug . '/{projectStatusPivot}', static::class)
->middleware(static::getMiddlewares())
->name($slug);
};
}
does not work and the generated route is admin/project-status?projectStatusPivot=2. How can I configure the page in order to make it work with the route admin/project-status/2 ? Thanks in advance
Solution:
I think if you just override getRoutePath, or if you want more control override overriding the routes method it should let you do what you're after? https://github.com/filamentphp/filament/blob/f93758a103e79fd74200f29ebcef97368a96abb8/packages/panels/src/Pages/Concerns/HasRoutes.php#L36-L39...
Jump to solution
2 Replies
Solution
ConnorHowell
ConnorHowell10mo ago
I think if you just override getRoutePath, or if you want more control override overriding the routes method it should let you do what you're after? https://github.com/filamentphp/filament/blob/f93758a103e79fd74200f29ebcef97368a96abb8/packages/panels/src/Pages/Concerns/HasRoutes.php#L36-L39
TheWiseG
TheWiseGOP10mo ago
it works, thanks.
Want results from more Discord servers?
Add your server