Source: martinjoo.dev

Blog for Laravel Artisans
What Is Domain-Driven Design or DDD? Domain-Driven Design is a software development approach that tries to bring the business language and the source code as close as possible.

Now we can use the state classes like this: class OrderController extends Controller { public function update(UpdateOrderRequest $request, Order $order) { abort_if(!$order->status->canBeChanged(), 400); }}

This is a concrete Transition: class DraftToPendingTransition implements Transition { public function execute(Order $order): Order { if ($order->state::class !== DraftOrderStatus::class) { throw new Exception('Transition not allowed'); } $order->state_class = PendingOrderStatus::class; $order->save(); return $order; }}

The last piece of the puzzle is the Controller: class ChangeOrderStatusController extends Controller { public function __construct(private ChangeOrderStatusAction $changeOrderStatus) { } public function index(Order $order, string $state) { $nextOrderStatus = OrderStatuses::from($state)->createOrderStatus($order); return [ 'data' => new OrderResource($this->changeOrderStatus->execute($order, $nextOrderStatus))]; }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners