0

This is the scenario: I have two tables i.e Student and Guardian. They all have one form as stated below The Form

I want when the form is submited. It creates a student gets the student Id and also adds the guardian data along with the student id.

The relationship between the student and guardian is a hasMany Relationship.

  • When you click on the student from the listing, then it will show the guardian details, right? – Mitesh Rathod Jul 27 '23 at 12:21
  • Not really, My desire is to enter the student and parent data at once though both are stored in different tables. The parent table stored the student id. so when creating the student the id is captured and passed as a variable while creating the guardian/parent – Akampurira Brian David Jul 27 '23 at 16:53

1 Answers1

0

This should not be a problem. You can customise the CreateAction in getActions() method by using using() method on Filament\Pages\Actions\CreateAction like this.

protected function getActions(): array
    {
        return [
            Actions\CreateAction::make()
                ->using(function (array $data): Model {
                    $student = static::getModel()->create($studentData);
                    $student->guardian()->create($guardianData);

                    return $student;
                }),
        ];
    }

Ehs4n
  • 762
  • 1
  • 8
  • 24