1. Go to this page and download the library: Download padosoft/laravel-routines 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/ */
padosoft / laravel-routines example snippets
use Padosoft\Routines\Contracts\Target\{RoutineTarget, TargetDescriptor, TargetResult, ValidationResult};
use Padosoft\Routines\Contracts\Execution\RoutineExecution;
final class SendDigestTarget implements RoutineTarget
{
public function type(): string { return 'digest'; }
public function descriptor(): TargetDescriptor
{
return new TargetDescriptor(
label: 'Digest by email',
summary: 'Sends the period summary to an address.',
fields: ['email' => ['label' => 'Recipient', 'type' => 'email', 's retries:
// it is what stops the second email from going out after a timeout.
Mail::to($execution->payload('email'))->send(
new Digest($execution->scheduledFor, $execution->timezone, $execution->idempotencyKey)
);
return TargetResult::succeeded('Digest sent.', cost: 0.001);
}
}
// From your EventServiceProvider
Event::listen(OrderPlaced::class, function (OrderPlaced $event): void {
app(EventTrigger::class)->handle('order.placed', $event);
});
$secret = app(RoutineManager::class)->rotateWebhookSecret($routine);
// Returned in clear ONCE: from here on it only exists encrypted in its column.
// config/routines.php
'lock_seconds' => 900, // longer than the slowest fire you expect
'catch_up_cap' => 25, // a downtime must not become a swarm
'retry_base_seconds' => 60, // exponential backoff: 1', 2', 4', 8'…
'targets' => [
'job' => [
'enabled' => true,
// Empty by default, and deliberately so.
'allowed' => [App\Jobs\SendDailyDigest::class],
],
],
use Padosoft\Routines\Testing\TargetContract;
final class InvoiceReminderTargetTest extends TestCase
{
public function test_it_respects_the_routine_target_contract(): void
{
TargetContract::assertAll(
new InvoiceReminderTarget(...),
validPayload: ['template' => 'reminder'],
invalidPayload: ['template' => ''],
// The "outside the mandate" case is expressed either as fire input or as
// configuration, because real targets decide in both ways:
outOfMandatePayload: ['template' => 'reminder', 'write_off_days' => 365],
);
}
}