Set default value for inputs
I'm having trouble setting the default data for my form. Please help
10 Replies
I have tried
// dd($company);
$this->company = $company;
// dd($this->company);
$this->form->fill([
'company_name' => $company->company_name,
]);
$this in your context is the livewire component or the field, not the model. But also you can’t use a relationship for default because the model doesn’t exist in the create content. If you want a default you will need to do a manual query against the company table to get a default record for the company relationship.
Also be aware that default() on works in the context of creating a record.
@awcodes I see, I’m trying to have users edit their information with this code.
try to share the whole code that you are using (code not image please)
@Leandro Ferreira This is a sample
This is what I get when I dump the $company in
Where is your
$form
? Are you using a statePath
?
Check this section: https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#adding-the-form
If you are filling the company_name in the mount method, you don't need ->default(xx)
@Leandro Ferreira Can I add the image to the fileupload field??
Yes
@Leandro Ferreira this is what I did