How to retrieve id from url and insert as default value in TextInput?
Inside a form in a resource page, i need to retrieve the record id (in this case 1) from the following url: /admin/products/1/create-variant, and set it as default value inside a text input. request()->route()->parameter('record') returns null when included in the default value.
I am using the following code:
```
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('product_id')
->default( // What to insert here? )
->required(),
])
}
4 Replies
Default only works in the create context
And in the edit context you shouldn’t have to do this because it would already be set on the record.
Yes this is what i need, so how can i do that in the create context?
In the create context there is no record yet so you’ll have to handle it in one on the form lifecycle hooks. https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving