Auto Creating Child Model from Parent Resource

Hello, I have two Resources/modes, Appointment and Client Every appointment has a BelongsTo relation called client() Clients have hasMany appointments. I created the resources with --generate, and on the appointments create page, I can only put in the details of the appointment and choose an existing client from a select box. However, I want to create the client while Im creating the appointment. In other words, I want the fields of client creation to be shown in the appointment creation page, and on submit filament should first create the client, and then automatically handle the relationship. I have tried relationshipmanager and it only works for editing and viewing but not creating. I have tried to add the client fields manually
class AppointmentResource extends Resource
{
...

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make('Client')
->relationship('client')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->required()
->maxLength(255),
...
]),
Forms\Components\DateTimePicker::make('start_datetime')
->required(),
Forms\Components\DateTimePicker::make('end_datetime')
->required(),
...
class AppointmentResource extends Resource
{
...

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make('Client')
->relationship('client')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('phone_number')
->tel()
->required()
->maxLength(255),
...
]),
Forms\Components\DateTimePicker::make('start_datetime')
->required(),
Forms\Components\DateTimePicker::make('end_datetime')
->required(),
...
but it gives an error that client_id is required Is this possible?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server