How to run cron job based on database entries using laravel?

Viewed 884

In my application I am using one functionality which I need to run on a specific time. I saved that time in my database. Based on that my scheduler will run the functionality. Currently I have used cron method which run that functionality every particular minutes. But not run cron at the minutes like 2,3,4 etc. or any other any time. How can I run that? Is there any specific method which take any values and based on that it run cron?

2 Answers

If I understood, you want to execute a cron command on specific date/time? You could do this by using when method with closure function inside your schedule cron command, which will execute if given date/time is returned true. Do something like this:

$schedule->command('your:command')
            ->when(function(){
               return ('your condition goes here');
            });

So if your condition is true, this command will execute.

you run crob job in 2 ways:

  1. write function in controller and write route for that function. and set that function route in cron job.

set cron like this :

wget -O -q -t 1 {url of that function}

for example : wget -O -q -t 1 http://domian.com/xyz/advertisement_expire_if_not_print
  1. using scheduler
Related