1. Go to this page and download the library: Download dayemsiddiqui/laravel-saga 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/ */
dayemsiddiqui / laravel-saga example snippets
return [
];
use dayemsiddiqui\Saga\SagaStep;
class FirstStep extends SagaStep
{
protected function run(): void
{
// Your business logic here
// You can access $this->context to share data between steps
$this->context()->set('foo', 'bar');
}
}
class SecondStep extends SagaStep
{
protected function run(): void
{
// Access data from previous steps
$foo = $this->context()->get('foo');
// More business logic...
}
}
use dayemsiddiqui\Saga\Saga;
// Optionally, use the facade: use Saga;
$saga = Saga::named('My Example Saga')
->chain([
FirstStep::class,
SecondStep::class,
])
->dispatch();
use dayemsiddiqui\Saga\Saga;
use Pest\Laravel\test;
test('example saga is dispatched', function () {
Saga::fake();
// Run the code that dispatches your saga
// ...
Saga::assertDispatched('My Example Saga');
});
Saga::assertDispatched('My Example Saga', [
FirstStep::class,
SecondStep::class,
]);