phplaravelproductiondev-to-productionlaravel-jetstream

Implementing some function in the background - Laravel


I'm new to laravel and I got a question that is driving me crazy. I have a web application with laravel 8/jetstrean/taiwind css on a shared host and I need to run some specific functions o the background (like sending email whenever a user has been x months working in the platform). So I would like your help to know how to do the following:

Any help would be very appreciated. thanks in advance...


Solution

  • Have a look at scheduling:

    https://laravel.com/docs/8.x/scheduling

    You can create commands that are scheduled to run at the intervals you want.

    https://laravel.com/docs/8.x/artisan

    If you write the logic in the command to check which users have been working x months, you can then send those users an email.

    You will need to set up the scheduler to use a cron job.

    The cron job will run the main Laravel scheduler, which then can run Console commands at different intervals.

    The documentation explains how to do this.

    https://laravel.com/docs/8.x/scheduling#running-the-scheduler

    --

    For bonus points, you can dispatch a Job, that sends the email

    https://laravel.com/docs/8.x/queues#creating-jobs

    Or you can trigger an Event and have a Listener that sends the emails

    https://laravel.com/docs/8.x/events