Help on setting up multi-model Resource management through single page

Hi guys, I'm kinda new to Filament and Laravel and I am trying to put together an application that can be used to manage appointments for companies, to accomplish this I am trying to setup a single Resource page to manage a Model and its underlying relationships (see screenshot and description below) Description of the class-diagram - A user is a member of Company (Tenant) - A service belongs to a company (For example: nailpolish) - A service can have one or more schedules (days of week) - A schedule can have one or more timeslots What am I trying to accomplish? I want to be able to create a Service using a ServiceResource. However for this service I also want to be able to manage the corresponding Schedule and Timeslots, all from the same EditResource page as they belong together What have I tried so far? This is the Form I am using to create and edit the Service currently:
return $form
->schema([
TextInput::make('name')->required()->maxLength(255)->label('Service naam'),
TextInput::make('price')->numeric()->prefix('€')->maxValue(42949672.95)->label('Prijs'),
TextInput::make('duration')
->label('Duur van service')
->placeholder('e.g., 01:30')
->rule('regex:/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/')
->helperText('Gebruik het formaat HH:mm (24-uurs klok)'),
TextInput::make('description')->required()->maxLength(1000)->columnSpan('full')->label('Beschrijving'),
FileUpload::make('imageUrl')->columnSpan('full')->label('URL naar afbeelding'),
Select::make('schedule_id')->label('Tijdsloten')->searchable()->multiple()
->relationship('schedules', 'day_of_week')->preload()
->createOptionForm([
Select::make('day_of_week')->options(DayOfWeek::class)->required()->label('Dag van de week'),
Repeater::make('slots')->label("Tijdssloten")->relationship()->schema([
TimePicker::make('start')
->prefixIcon('heroicon-o-paper-airplane')
->seconds(false)
->required(),
TimePicker::make('end')
->prefixIcon('heroicon-o-paper-airplane')
->seconds(false)
->required(),
Checkbox::make('available')->label('Beschikbaar'),
])->columnSpanFull()
])
]);
return $form
->schema([
TextInput::make('name')->required()->maxLength(255)->label('Service naam'),
TextInput::make('price')->numeric()->prefix('€')->maxValue(42949672.95)->label('Prijs'),
TextInput::make('duration')
->label('Duur van service')
->placeholder('e.g., 01:30')
->rule('regex:/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/')
->helperText('Gebruik het formaat HH:mm (24-uurs klok)'),
TextInput::make('description')->required()->maxLength(1000)->columnSpan('full')->label('Beschrijving'),
FileUpload::make('imageUrl')->columnSpan('full')->label('URL naar afbeelding'),
Select::make('schedule_id')->label('Tijdsloten')->searchable()->multiple()
->relationship('schedules', 'day_of_week')->preload()
->createOptionForm([
Select::make('day_of_week')->options(DayOfWeek::class)->required()->label('Dag van de week'),
Repeater::make('slots')->label("Tijdssloten")->relationship()->schema([
TimePicker::make('start')
->prefixIcon('heroicon-o-paper-airplane')
->seconds(false)
->required(),
TimePicker::make('end')
->prefixIcon('heroicon-o-paper-airplane')
->seconds(false)
->required(),
Checkbox::make('available')->label('Beschikbaar'),
])->columnSpanFull()
])
]);
This makes it possible for me to: - Create a Service accordingly - Create a Schedule with the required schedules However, I am no longer able to edit and delete the attached schedules and time slots per schedule (see screenshot) Is anyone able to point me to some documentation on how to solve the issue I am facing or maybe have some example code that I can look into to learn from? Or is it better to do this the other way around and assign a Schedule to a Service from a ScheduleResource page? Thanks a lot in advance!
No description
No description
1 Reply
Tally
Tally3w ago
I would consider making a custom form field for this use case Little bit more development but more flexible

Did you find this page helpful?