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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners