Please show the submit action as well
Flush Livewire session property
Hi, I have a form property in my full page component:
#[Session(key: 'nomineeForm')]
public NomineeForm $nomineeForm;
It's a simple Livewire Form:
class NomineeForm extends Form
{
#[Validate(['required', 'string', 'max:255'])]
public string $name = '';
#[Validate(['required', 'email', 'max:255', 'unique:nominations,email'])]
public string $email = '';
#[Validate(['required', 'string', 'max:255'])]
public string $company_name = '';
}
Everything works fine, but I would like to clear this session after the form is submitted. I've tried adding the forget function to my submit method, but when I reload the page, the form is still prefilled and the session still exists:
session()->forget('nomineeForm');
When I add dd(session()->all()); after this forget line, I don't see my nomineeForm session, but when the page is reloaded, it's still there.
I also tried session()->flush(); but got the same result.
I figured out that there's no need to call session()->forget() or any other session-related methods. Simply calling reset() on the form object does the job:
public function submit(): void
{
app(CreateNominationAction::class)->run(
type: $this->type,
nomineeForm: $this->nomineeForm,
);
$this->nomineeForm->reset();
}
Please or to participate in this conversation.