Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DivDax's avatar
Level 10

Set field default with url GET parameter

I'd like to set the default value for a field with a get paramter for my create form. For my field i use the default() method, but i can't access the initial get paramter (exmaple.com/contact/new?name=defaultName):

Text::make('Name', 'name')->default(function(NovaRequest $request) {
    return $request->get('name');
}),

Any idea how i can set the default value by a get parameter?

0 likes
6 replies
christian-qode's avatar

Not sure what the NovaRequest class does, maybe you can use the regular Illuminate\Http\Request class?

DivDax's avatar
Level 10

NovaRequest extends the default Request class. I also used the request() helper but i dont get the initial get paramters. When loading e.g. exmaple.com/contact/new?name=defaultName the page loads and then the component/fields are loaded without my paramter.

DivDax's avatar
Level 10

@nakov even inline it doesnt work, because i can't access my url parameter.

request()->all():

array:6 [▼
  "editing" => "true"
  "editMode" => "create"
  "inline" => "false"
  "viaResource" => null
  "viaResourceId" => null
  "viaRelationship" => null
]
DivDax's avatar
Level 10

@Nakov Thank you! 🥳❤️🙏 Working with the referer url did the trick.

Please or to participate in this conversation.