Diego Cespedes Diego Cespedes - 11 months ago 50
Javascript Question

Run function controller when date expired

I am working on a new project where User public add with a expire date,

In my database I have

like this picture:
enter image description here

I would like to run a function of my controller when add will expired.

I would like to send an email and do other features.

I don't know if this is possible with laravel php framework.

I'm working with laravel 5.2.

I can pass the expire date and date of creation add to my view.

I saw that with JavaScript I can use interval and create a countdown time, but I don't know if I can run a function after countdown finish.

Answer Source

Assuming your model is User add your App/Console/Kernel.php under the function scheduler do something like:

 $schedule->call(function () {
            foreach (User::all() as $user) {
                if (Carbon::now() > $user->expire_date) {
                     // Do what you have to do

To test it run php artisan schedule:run

if it work add on your cron:

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1