How to send parameter to CreateAction?
I have a dinamic page to list Questions Models based by url query string altering query on table like this:
on List resource i have a CreateAction button. How can i send to this modal current request value?
7 Replies
What do you mean by 'current request value'?
On QuestionResource i get module_id by request()->route('record), and modify query for table. But i don't know how to pass this "module_id" to createAction modal (i need to use it on select)
Have you tried to just access the request data within the form?
Yes… it returns null
You're kind of hacking around something filament will already deal with for you.
The module should be a resource, for which you are best off with a view page for each module.
The Questions should be a relation manager class of the module resource.
Then you have access to things like
getOwnerRecord
, although you can get by without even that.Few days ago, I do something like that.., on the relationmanager table have a table header action
Tables\Actions\CreateAction::make()
->label(__('general.create') . ' ' . lcfirst(__('general.record')))
->icon(MedicalExamResource::getNavigationIcon())
->url(MedicalExamResource::getUrl('create', ['employee' => $this->getOwnerRecord()->id])),
Next on the create page
protected function fillForm(): void
{
if(request()->employee) {
$employee = Employee::find(request()->employee);
$this->form->fill([
'customer_id' => $employee->customer_id,
'employee_id' => $employee->id,
'type' => $employee->medicalExams->isEmpty() ? 'entry' : 'periodic',
'job_factors' => JobFactorService::getEmployeeJobFactorsToFillMedicalExamFormSelect($employee),
'job_activities' => JobActivitiesService::getEmployeeJobActivitiesToFillMedicalExamFormSelect($employee),
]);
} else {
$defaultCustomerId = MedicalExamService::getCustomersWithAllowedMedicalExamsCountByRole() === 1
? MedicalExamService::getCustomersWithAllowedMedicalExamsIdsByRole()[0]
: null;
$this->form->fill([
'customer_id' => $defaultCustomerId,
'employee_id' => null,
'type' => null,
'job_factors' => [],
'job_activities' => [],
]);
}
}
thank you so much @Matthew @Sydd