What do you think is the best way to do this?

I have a schedule table where users can enter their schedules. Based on that schedule (which should be hours a o'clock or half past) I create slots (in the slots table of my database) of 30 min to schedule appointments. Here is an example:

The user sets his schedule on Mondays from 10:00 to 12:00. When saving it in the Schedule table, the following available slots are automatically created in the slots table like this:

(FK) schedule_id: 1
time_start: 10:00
time_end: 10:30
status: 'available

(FK) schedule_id: 1
time_start: 10:30
time_end: 11:00
status: 'available

(FK) schedule_id: 1
time_start: 11:00
time_end: 11:30
status: 'available

(FK) schedule_id: 1
time_start: 11:30
time_end: 12:00
status: 'available

should I work with a custom function in the Create file of my Schedules resource (CreateSchedule)? maybe something with beforeCreate()? what do you suggest me?
Btw, currently the user already has the Schedule tab, where he can enter the day, and the start and end time of his working day. I would like some suggestion on how to implement the slots.


Thanks in advance
Solution
sorry I didn't answer sooner. Thank you very much for replying. Unfortunately I am very tight on time and can't afford to follow a course right now. Anyway, in case anyone is interested, I'm doing it with the CreateSchedule page, adding some things in a afterCreate() function. Through this function, that is always executed everytime you create a schedule, I create the Slots. Is this the best way to do it? possibly not (certainly not). But it works and for the moment it works for me hahaha.
Was this page helpful?