PHP code example of rushing / laravel-schedule-runs

1. Go to this page and download the library: Download rushing/laravel-schedule-runs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rushing / laravel-schedule-runs example snippets


class MyCommand {
    use \Rushing\ScheduleRuns\Traits\HasScheduleRuns;

    protected $signature = 'app:my-command {--since=}';

    public function getScheduleRunHandle()
    {
        // The class name is used by default in the trait, but you can override here.
        return static::class;
    }

    public function handle()
    {
        $query = MyModel::query();

        // Get the last schedule run
        $this->getLastScheduleRun();

        // Modify a query to get items created or updated after the last schedule run. Optionally, pass an override parameter.
        $this->scopeWhereLastScheduleRun($query, ['created_at', 'updated_at'], '>=', $this->option('since'));

        // Clear the history
        $this->scheduleRuns()->delete(); // or each->delete() if you want to fire the model events.

        // Set the last run time, optionally with extra data attached.
        $this->setLastScheduleRun(now(), [
            'whatever' => 'you want'
        ]);
    }
}