0

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

In my database I have date_created and expire_date 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.

jwpfox
  • 5,124
  • 11
  • 45
  • 42
Diego Cespedes
  • 1,353
  • 4
  • 26
  • 47
  • 1
    Look into Artisan commands. You can create one that will check for expired records and do what you need, then schedule it either via cron or the command scheduler. – aynber Oct 17 '16 at 20:46

3 Answers3

0

I think you need add a cron job on your server and create your own logic as described here https://laravel.com/docs/5.2/scheduling

aleksejjj
  • 1,715
  • 10
  • 21
0

Basicaly you add to laravel framework https://laravel.com/docs/5.1/mail. Section queuing emails.

Mail::queue('emails.welcome', $data, function ($message) {
//change atributes
});

and then you can add countdown in php to laravel framework or use some predefined framework function which counts time.

From database you choose correct table and

SELECT expire_date FROM table_name
//take value from table and compare with current time
if ($row["expire_date"] == time() )

PHP Countdown to Date

Community
  • 1
  • 1
Matovidlo
  • 46
  • 6
0

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
                }
            }
        })->everyMinute();

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
Rocco Milluzzo
  • 997
  • 8
  • 16
  • 1
    Yes! it work! but i have a shared hosting, i uploaded all files, www.dixard.info/regalo/regalo , and i created a cron job like this: php /home/dixardin/public_html/regalo/regalo/laravel/artisan schedule:run >> /dev/null 2>&1 , the path arrive to the file artisan. But it doesnt work in my shared hosting. – Diego Cespedes Oct 18 '16 at 08:51
  • Contact them there should be a way to make a crontab work even on a shared hosting, maybe the path is different? – Rocco Milluzzo Oct 18 '16 at 10:44