1. Go to this page and download the library: Download ramir1/laravel-planner 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/ */
ramir1 / laravel-planner example snippets
use Illuminate\Console\Command;
use Ramir\Planner\Facades\Planner;
class AnonceBumpCommand extends Command
{
protected $signature = 'anonce:bump {anonce}';
public function handle(): int
{
$anonce = Anonce::find($this->argument('anonce'));
if (! $anonce) {
Planner::cancelGroup("anonce:{$this->argument('anonce')}", 'Anonce deleted');
$this->line('Anonce deleted');
return self::SUCCESS;
}
if (! $anonce->isPublished()) {
$this->line('Not published, nothing to do');
return self::SUCCESS;
}
$anonce->bump();
$this->line('Bumped');
return self::SUCCESS;
}
}
use Ramir\Planner\Facades\Planner;
Planner::schedule('anonce:bump', now()->addDay(), ['anonce' => $anonce->id], group: "anonce:{$anonce->id}");
Planner::schedule('anonce:bump 15', now()->addDays(2)); // arguments as a string
Planner::scheduleMany([ // one transaction
['command' => 'anonce:bump', 'run_at' => now()->addDay(), 'parameters' => ['anonce' => 15], 'group' => 'anonce:15'],
['command' => 'anonce:bump', 'run_at' => now()->addDays(2), 'parameters' => ['anonce' => 15], 'group' => 'anonce:15'],
]);
Planner::pending('anonce:15'); // pending + running runs of the group
Planner::lastRunAt('anonce:15'); // run_at of the last pending run, or null
Planner::cancelGroup('anonce:15');
if ($anonce->bumped_at?->isToday()) {
$this->line('Already bumped today');
return self::SUCCESS;
}