PHP code example of robersonfaria / laravel-database-schedule

1. Go to this page and download the library: Download robersonfaria/laravel-database-schedule 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/ */

    

robersonfaria / laravel-database-schedule example snippets

 artisan migrate


return [
    //...
    /**
     * If restricted_access is true, the user must be authenticated and meet the definition of `viewDatabaseSchedule` gate
     */
    'restricted_access' => env('SCHEDULE_RESTRICTED_ACCESS', true),
    //...
]

protected function gate()
{
    Gate::define('viewDatabaseSchedule', function ($user) {
        return in_array($user->email, [
            '[email protected]',
        ]);
    });
}

Gate::define('viewDatabaseSchedule', function ($user) {
     return $user->hasRole('administrator');
});

    /**
     * If you have a lot of jobs, you can group them for easier managing of jobs.
     */
    'enable_groups' => true,



namespace App\Console\Commands;

use Illuminate\Console\Command;

class test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:test {user} {initialDate} {finalDate}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $this->info('Hello ' . $this->argument('user'));
        $this->info("Initial Date: " . $this->argument('initialDate'));
        $this->info("Final Date: " . $this->argument('finalDate'));
        return 0;
    }
}

php artisan vendor:publish --provider="RobersonFaria\DatabaseSchedule\DatabaseSchedulingServiceProvider" --tag="config"
bash
php artisan schedule:run
bash
Running scheduled command: ('/usr/bin/php7.4' 'artisan' command:test 1 '2022-02-02 00:00:00' '2022-04-02 00:00:00' > 'path/to/storage/logs/schedule-8763d2ce5a20ee888dd9d8a7e5a5cfcd4b315375.log' 2>&1 ;
bash
$ php artisan schedule:list

+----------------------------------------------------------------------------------------+-----------+-------------+----------------------------+
| Command                                                                                | Interval  | Description | Next Due                   |
+----------------------------------------------------------------------------------------+-----------+-------------+----------------------------+
| '/usr/bin/php7.4' 'artisan' inspire                                                    | * * * * * |             | 2022-03-02 17:05:00 +00:00 |
| '/usr/bin/php7.4' 'artisan' command:test 1 '2022-02-02 00:00:00' '2022-04-02 00:00:00' | * * * * * |             | 2022-03-02 17:05:00 +00:00 |
+----------------------------------------------------------------------------------------+-----------+-------------+----------------------------+