Package
laravel-business-process
Laravel Business Process is a simple and clean way to run business process using a Laravel Pipeline, in a structured and type-safe way.
dev-main3,960 downloads66 stars
Laravel Business Process is a simple and clean way to run business process using a Laravel Pipeline, in a structured and type-safe way.
This package is inspired by the tutorial I wrote for Laravel News Going Past Actions in Laravel.
Installation
composer require juststeveking/laravel-business-processUsage
To get started with this package, all you need to do is create a new process class:
use JustSteveKing\BusinessProcess\Process;
final class PurchaseProduct extends Process{ protected array $tasks = [ CheckStockLevel::class, ProcessOrder::class, DecreaseStockLevel::class, NotifyWarehouse::class, EmailCustomer::class, ];}Our process class registers the tasks that need to be completed for this process to run, each task must implement the TaskContract interface that comes with this package.
use JustSteveKing\BusinessProcess\Contracts\TaskContract;
final class CheckStockLevel implements TaskContract{ public function __invoke(ProcessPayload $payload, Closure $next): mixed { // perform your logic here with the passed in payload.
return $next($payload); }}Your tasks are standard classes that the Pipeline class from Laravel would expect.
The payload is a class that implements ProcessPayload interface, signalling that it is a payload for a process. They are simple plain old PHP classes with no requirements to add methods.
use JustSteveKing\BusinessProcess\Contracts\ProcessPayload;
final class PurchaseProductPayload implements ProcessPayload{ public function __construct( // add whatever public properties you need here public int $product, public int $user, public int $order, ) {}}Finally, we can call this process within our controller/job/cli wherever you need to.
final class PurchaseController{ public function __construct( private readonly PurchaseProduct $process, ) {}
public function __invoke(PurchaseRequest $request, int $product): JsonResponse { try { $this->process->run( payload: $request->payload(), ); } catch (Throwable $exception) { // Handle exception }
// return response. }}Testing
To run the test:
composer run testCredits
LICENSE
The MIT License (MIT). Please see License File for more information.
Related
More Packages
mavis
Run a freelance business from plain files: clients, calls and follow-ups, time, quotes and invoices as Markdown, from one Go binary, with an MCP server for agents.
v0.1.3
PHPcloudevents
Cloud Events in PHP.
dev-main
PHPcompanies-house-laravel
A Laravel wrapper to get companies house information and validate company numbers
v1.2.0
Same subject
In other formats
The Second Pattern: Process Manager
Everyone calls it a Saga. Most of the time it is a Process Manager, and the muddle is why teams adopt the word and then never write the compensations it never promised them.
Architecture
VideoLaravel "clean" architecture - testing with pestPHP
In this stream we will be carrying on with our multi blogging platform in Laravel, attempting to find the balance between "best practice" and developer experience.
Architecture