Parameters for index and create is it possible?

Hello! I have a question, I hope you can help me. I created a resource with edit, create and index pages. I would like to know if I can pass parameters to these pages. Example: I created an action on the table that calls a resource (index) and another case the resource (create) but I would like to pass parameters to index and create, is there any way? Thanks.
Solution:
I think you still can do ->url(ListLicenses::getUrl(fn($record)=>['user_id'=>$record->user_id])) also this may help you more https://filamentphp.com/plugins/guava-nested-resources...
Filament
Nested Resources by Guava - Filament
Adds support for nested resources
Jump to solution
10 Replies
Lara Zeus
Lara Zeus13mo ago
how are you calling these links if you can share a code
calls a resource (index)
Maagalhaes
MaagalhaesOP13mo ago
I call it in my relation manager table like this: Action::make('create') ->icon('heroicon-m-pencil-square') ->iconButton() ->action(fn (?Model $record) => redirect()->route('filament.app.resources.contratos.create', $record)), In my ContratoResource: public static function getPages(): array { return [ 'index' => Pages\ListContratos::route('/'), 'create' => Pages\CreateContrato::route('/{record}/create'), 'edit' => Pages\EditContrato::route('/{record}/edit'), ]; } So I get this error: Missing required parameter for [Route: filament.app.resources.contratos.create] [URI: app/contratos/{record}/create] [Missing parameter: record].
Lara Zeus
Lara Zeus13mo ago
you can pass to the route ->route('filament.app.resources.contratos.create', ['record'=>$record,'foo'=>'bar'])
Maagalhaes
MaagalhaesOP13mo ago
The error remains Action::make('create') ->label('Criar contrato') ->action(fn (?Model $record) => redirect()->route('filament.app.resources.contratos.create', ['record' => $record])), I created the resource from the filament command. Looking at the create and index pages, they extend from CreatedRecord and ListRecords in the mount method, they do not receive the record unlike EditRecord. Could this be the case? If so, how can I get around it?
Lara Zeus
Lara Zeus13mo ago
the record part only for view and edit dont need them for create and list
Lara Zeus
Lara Zeus13mo ago
->url(ListContratos::getUrl())
Maagalhaes
MaagalhaesOP13mo ago
I want to do it like this: I have the user resource that has a relationship with contracts, this is listed within the user's own editing screen using relation manager. When clicking on add contract, I would like it to open the contract resource on the creation page, but to do so I would need to take that user's ID. Is this possible with resources or would I have to change the way I'm doing it? I know that by default the relation manager header already has an action to add a new record, but I really need to go to the resource, as there will be other relation managers inside.
Solution
Lara Zeus
Lara Zeus13mo ago
I think you still can do ->url(ListLicenses::getUrl(fn($record)=>['user_id'=>$record->user_id])) also this may help you more https://filamentphp.com/plugins/guava-nested-resources
Filament
Nested Resources by Guava - Filament
Adds support for nested resources
Maagalhaes
MaagalhaesOP13mo ago
Thanks! It worked using url(). I liked the plugin, I'm going to test it in my application.

Did you find this page helpful?