Bromira's avatar

Permissions Structure Advice

First of all, I'd like to say thank you for reading/helping!

I'm not necessarily looking for any code, but more for suggestions on how to generate follow-up meetings for absences within my app.

The process should be:

  1. A manager registers an absence event.
  2. After 1 week the system generates a "keep in touch" event (it's a model with some basic questions). 2a. If a previous "keep in touch" event is missed, "close" (just a "completed_at" datetime field & "status" string field to track it wasn't completed) it and generate a new one.
  3. After every 2x "keep in touch" events, a notification is sent to an administrator.
  4. Once an absence has been completed, all previous "keep in touch" models are closed as status "missed".

I obviously have the registration of an absence event already working and have the model/interface for "keep in touch" events plus a "task" system.

I'm more asking how I'd go about generating the keep in touch events.

I was thinking about adding a field to the absence table "last_keep_intouch" as a datetime and every night at midnight checking if 7 days have lapsed, closing any previous open events & checking if the number of previous events is odd or even to generate the additional task.

I'm just wondering if there's a better way built into Laravel.

Thanks again!

0 likes
1 reply
LaryAI's avatar
Level 58

One possible solution is to use Laravel's task scheduling feature to run a command every day at midnight that checks for absence events that are due for a "keep in touch" event. Here's an example implementation:

  1. Create a new command using php artisan make:command GenerateKeepInTouchEvents.

  2. In the handle method of the command, query for absence events that are due for a "keep in touch" event (i.e. their last "keep in touch" event was more than 7 days ago). For each absence event, create a new "keep in touch" event and save it to the database.

  3. In the same handle method, check for "keep in touch" events that were missed (i.e. their due date has passed and they haven't been completed yet). For each missed event, mark it as "closed" and create a new one.

  4. Finally, check for absence events that have completed and mark all their "keep in touch" events as "missed".

  5. Schedule the command to run every day at midnight using Laravel's task scheduling feature. Add the following line to your app/Console/Kernel.php file:

protected function schedule(Schedule $schedule)
{
    $schedule->command('generate:keep-in-touch-events')->dailyAt('00:00');
}

This will run the generate:keep-in-touch-events command every day at midnight.

Note: This is just one possible solution and there may be other ways to implement this feature.

Please or to participate in this conversation.