06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Task Scheduling 462<br />

Task Output<br />

The Laravel scheduler provides several convenient methods for working with the output generated<br />

by scheduled tasks. First, using the sendOutputTo method, you may send the output to a file for later<br />

inspection:<br />

1 $schedule->command('emails:send')<br />

2 ->daily()<br />

3 ->sendOutputTo($filePath);<br />

If you would like to append the output to a given file, you may use the appendOutputTo method:<br />

1 $schedule->command('emails:send')<br />

2 ->daily()<br />

3 ->appendOutputTo($filePath);<br />

Using the emailOutputTo method, you may e-mail the output to an e-mail address of your choice.<br />

Note that the output must first be sent to a file using the sendOutputTo method. Also, before e-<br />

mailing the output of a task, you should configure Laravel’s e-mail services:<br />

1 $schedule->command('foo')<br />

2 ->daily()<br />

3 ->sendOutputTo($filePath)<br />

4 ->emailOutputTo('foo@example.com');<br />

Note: The emailOutputTo and sendOutputTo methods are exclusive to the command method<br />

and are not supported for call.<br />

Task Hooks<br />

Using the before and after methods, you may specify code to be executed before and after the<br />

scheduled task is complete:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!