F
Filament16mo ago
Ander

relationship on a resource

I need a relationship on a resource, my main table is "employee", my secondary table is "employeeJob" this get "employee_id", what I try to do is that my form obtains the data from the "employeeJob" table, so that I can also edit them with the other records of "employee", its posible?. try to do something like this: look picture for saved the data, i use: protected function handleRecordCreation(array $data): Model { $employee = static::getModel()::create($data); $current_date = Carbon::today(); $job = Job::where('id', $data['job_id'])->first(); $job = EmployeeJob::create([ 'employee_id' => $employee->id, 'job_id' => $data['job_id'], 'title' => $job->name, 'type' => $data['type'], 'payment_amount' => $data['payment_amount'], 'payment_unit' => $data['payment_unit'], 'start_date' => $current_date ]); return $employee; }
7 Replies
DanielvdSpoel
DanielvdSpoel16mo ago
Pretty sure you have to put it in a section or something similar And then you can use the ->relationship() method
bwurtz999
bwurtz99916mo ago
For a select element, you need to use ->relationship()
Ander
AnderOP16mo ago
and the textinput?
DanielvdSpoel
DanielvdSpoel16mo ago
As long as it is in the section it should work
Ander
AnderOP16mo ago
thanks to all, i solved like this: Fieldset::make('') ->relationship('employeeJob') ->schema([...])
Want results from more Discord servers?
Add your server