F
Filament2mo ago
Xavi

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:
return $table
->query(function () {
return Question::query()->where('module_id', request()->route('record'));
})
->columns([
Tables\Columns\TextColumn::make('subject')
->searchable()
->sortable(),
]);
return $table
->query(function () {
return Question::query()->where('module_id', request()->route('record'));
})
->columns([
Tables\Columns\TextColumn::make('subject')
->searchable()
->sortable(),
]);
on List resource i have a CreateAction button. How can i send to this modal current request value?
7 Replies
Matthew
Matthew2mo ago
What do you mean by 'current request value'?
Xavi
XaviOP2mo ago
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)
Matthew
Matthew2mo ago
Have you tried to just access the request data within the form?
Xavi
XaviOP2mo ago
Yes… it returns null
Matthew
Matthew2mo ago
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.
Sydd
Sydd2mo ago
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' => [], ]); } }
Xavi
XaviOP2mo ago
thank you so much @Matthew @Sydd
Want results from more Discord servers?
Add your server