Laravel Action Classes Pattern
January 16, 2026
•
1 min read
•
21 views
Table of Contents
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);
}
}
Related Posts
Laravel Sanctum API Authentication Complete Guide
Build secure API authentication with Laravel Sanctum for SPAs and mobile apps.
Laravel Rate Limiting: Protect Your Application
Implement rate limiting to protect your Laravel application from abuse.
Laravel Blade Components: Build Reusable UI
Create powerful reusable components with Laravel Blade.
Comments (0)
No comments yet. Be the first to comment!