Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Laravel Custom Class/Model Scheduling
//Don't forget to change the namespace!
namespace App\Traits;
use Cron\CronExpression;
use Illuminate\Support\Carbon;
use Illuminate\Console\Scheduling\ManagesFrequencies;
trait Schedulable{
use ManagesFrequencies;
protected $expression = '* * * * *';
protected $timezone;
public function isDue(){
$date = Carbon::now();
if ($this->timezone) {
return CronExpression::factory($this->expression)->isDue($date->toDateTimeString());
public function nextDue(){
return Carbon::instance(CronExpression::factory($this->expression)->getNextRunDate());
public function lastDue(){
return Carbon::instance(CronExpression::factory($this->expression)->getPreviousRunDate());
Copy link

Thanks for sharing!

Copy link

Thank you for this trait!

Copy link

Thanks for this! Exactly what I needed, gave me the right path forward.

Copy link

Thank you David, you are the best!

Copy link

Thank you. Excellent solution!

Copy link

Thanks! Just what I needed for my current Project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment