F
Filament15mo ago
rabol

Problems pasing parameters to pages in a plugin

I'm having trouble to pass parameters to a page my log viewer plugin. I'm using Sushi as my 'record' so I cannot have a normal Filament resource I have 3 pages the main page that list the log files - works, no problem the log file page that lists the entries in the log file - some how it works the log file entry page that shows details of a log entry - does not work at all all 3 pages is registered in the plugin like this:
public function register(Panel $panel): void
{

$panel
->pages([
LogViewerPage::class,
LogViewerViewLogPage::class,
LogViewerViewDetailsPage::class,
]);
}
public function register(Panel $panel): void
{

$panel
->pages([
LogViewerPage::class,
LogViewerViewLogPage::class,
LogViewerViewDetailsPage::class,
]);
}
In LogViewerPage I have a table, and this is how I generate the actions
protected function getTableActions(): array
{
return [

Tables\Actions\Action::make('viewlogfile')
->label('View')
->url(function (LogFile $record) {
return LogViewerViewLogPage::getUrl(['fileName' => $record->name]);
}),

Tables\Actions\Action::make('delete')
->action('deleteLogFile')
->requiresConfirmation()
->hidden(fn ($record) => ! static::canDelete($record)),

];
}
protected function getTableActions(): array
{
return [

Tables\Actions\Action::make('viewlogfile')
->label('View')
->url(function (LogFile $record) {
return LogViewerViewLogPage::getUrl(['fileName' => $record->name]);
}),

Tables\Actions\Action::make('delete')
->action('deleteLogFile')
->requiresConfirmation()
->hidden(fn ($record) => ! static::canDelete($record)),

];
}
in LogViewerViewLogPage the mount() throws an error Unable to resolve dependency [Parameter #0 [ <required> $fileName ]] in class Rabol\FilamentLogviewer\Pages\LogViewerViewLogPage the url looks like this:
/admin/log-viewer-view-log-page?fileName=worker.log
/admin/log-viewer-view-log-page?fileName=worker.log
public function mount($fileName): void
{
$this->log = LogReader::filename($fileName);
$this->logEntries = $this->log->get(); // we need to paginate...
self::$title = 'Log file: '.$fileName;
$this->fileName = $fileName;
}
public function mount($fileName): void
{
$this->log = LogReader::filename($fileName);
$this->logEntries = $this->log->get(); // we need to paginate...
self::$title = 'Log file: '.$fileName;
$this->fileName = $fileName;
}
any hint on what I'm missing ?
6 Replies
Lara Zeus
Lara Zeus15mo ago
you're passing the fileName as query string not route parameters I think it should be /admin/log-viewer-view-log-page/worker.log
rabol
rabolOP15mo ago
I'm doing like this:
return LogViewerViewLogPage::getUrl(['fileName' => $record->name]);
return LogViewerViewLogPage::getUrl(['fileName' => $record->name]);
it worked fine in V2
Lara Zeus
Lara Zeus15mo ago
🤔 getUrl('index',['fileName' => $record->name])
rabol
rabolOP15mo ago
no this is for resources, first parameter should be array on a page
public static function getUrl(array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
{
$parameters['tenant'] ??= ($tenant ?? Filament::getTenant());

return route(static::getRouteName($panel), $parameters, $isAbsolute);
}
public static function getUrl(array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
{
$parameters['tenant'] ??= ($tenant ?? Filament::getTenant());

return route(static::getRouteName($panel), $parameters, $isAbsolute);
}
it is as if my page is not registered to accept parameters @Dan Harrin how to register pages in a plugin so that it can accept parameters ?
Lara Zeus
Lara Zeus15mo ago
$panel->pages([

]);
$panel->pages([

]);
in the packagePlugin
rabol
rabolOP15mo ago
not where, but how as I described above - I'm doing that in a resource one can do this: public static function getPages(): array { return [ 'index' => Pages\ListUserDocs::route('/'), 'create' => Pages\CreateUserDoc::route('/create'), 'view' => Pages\ViewUserDoc::route('/{record}'), 'edit' => Pages\EditUserDoc::route('/{record}/edit'), 'details' => Pages\UserDocDetails::route('/{record}/details'), 'pdf' => Pages\UserDocPDF::route('/{record}/pdf'), ]; } but not for pages as far as I can see
Want results from more Discord servers?
Add your server