Laravel

Laravel Action Classes Pattern

January 16, 2026 1 min read 21 views

Action classes pattern:

Create Action

class CreateUserAction
{
    public function execute(array $data): User
    {
        $user = User::create($data);
        event(new UserCreated($user));
        return $user;
    }
}

Use in Controller

public function store(Request $request, CreateUserAction $action)
{
    $user = $action->execute($request->validated());
    return redirect()->route('users.show', $user);
}

With Dependencies

class ProcessOrderAction
{
    public function __construct(
        private PaymentGateway $payment,
        private NotificationService $notifications
    ) {}

    public function execute(Order $order): void
    {
        $this->payment->charge($order);
        $this->notifications->orderConfirmed($order);
    }
}
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!