Nov 20, 2014 | laravel, 5.0, laravel 5

Laravel 5.0 - Event Scheduling

Series

This is a series of posts on New Features in Laravel 5.0.

!
Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.

Eric Barnes has a longer write up on this, so I'll just keep it short:

Laravel 5.0 is introducing a pretty incredible cron-style scheduler (similar to Indatus' Dispatcher) built into the core. Just point a cron job that's scheduled once a minute at artisan schedule:run and you're good to go.

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

For example, you can now bind the following event to clear your auth reminders daily:

$schedule
    ->command('auth:clear-reminders')
    ->daily()
    ->sendOutputTo($logPath)
    ->emailOutputTo('me@me.com');

You can use commmand() to call artisan commands, call to call methods or functions, or terminal() to run command line scripts:

$schedule->call('YourClass@someMethod')->twiceDaily();
$schedule->call(function() {
    // Do stuff
})->everyFiveMinutes();
$schedule->terminal('cp oldThing newThing')->dailyAt('8:00');

You can also use a callback to decide when something will or won't run, using when() or skip():

$schedule
    ->call('Mailer@BusinessDayMailer')
    ->weekdays()
    ->skip(function(TypeHintedDeciderClass $decider)
    {
        return $decider->isHoliday();
    }
);

This is just a quick introduction, though; check out Eric's post for a fuller rundown: Laravel 5 Scheduler on Laravel-News


Comments? I'm @stauffermatt on Twitter


Tags: laravel  •  5.0  •  laravel 5


This is part of a series of posts on New Features in Laravel 5.0:

  1. Sep 10, 2014 | laravel, 5.0, laravel 5
  2. Sep 10, 2014 | laravel, 5.0, laravel 5
  3. Sep 12, 2014 | laravel, laravel 5, 5.0
  4. Sep 20, 2014 | laravel, 5.0, laravel 5
  5. Sep 28, 2014 | laravel, laravel 5, 5.0
  6. Sep 30, 2014 | laravel, 5.0, laravel 5
  7. Oct 9, 2014 | laravel, 5.0, laravel 5
  8. Oct 10, 2014 | laravel, 5.0, laravel 5
  9. Oct 10, 2014 | laravel, 5.0, laravel 5
  10. Nov 20, 2014 | laravel, 5.0, laravel 5
  11. Jan 2, 2015 | laravel, 5.0, commands, laravel 5
  12. Jan 16, 2015 | laravel, laravel 5
  13. Jan 19, 2015 | laravel 5, laravel
  14. Jan 21, 2015 | laravel, events, 5.0, laravel 5
  15. Jan 26, 2015 | laravel, laravel 5
  16. Feb 1, 2015 | laravel, laravel 5
  17. Feb 14, 2015 | laravel 5, laravel, eloquent

Subscribe

For quick links to fresh content, and for more thoughts that don't make it to the blog.