---
title: "Laravel 13 Action Classes Example"
url: "https://magecomp.com/blog/laravel-13-action-classes/"
date: "2026-07-24T13:06:27+00:00"
modified: "2026-07-24T13:06:29+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "Laravel"
word_count: 562
reading_time: "3 min read"
summary: "Action Classes are used to keep controllers clean, as it helps in extracting logic to dedicated classes instead of cluttering controllers with logic. The usage of Reusable Action classes in an appl..."
description: "Learn how to implement Action Classes in Laravel 13 with practical examples."
keywords: "Laravel"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Choose Best Laravel Developer?"
    url: "https://magecomp.com/blog/choose-best-laravel-developer/"
  - title: "How to Create a User with Laravel’s firstOrCreate Method?"
    url: "https://magecomp.com/blog/create-user-laravel-firstorcreate-method/"
  - title: "How to Use ApexCharts in Laravel 11 with Larapex Charts?"
    url: "https://magecomp.com/blog/apexcharts-laravel-11-with-larapex-charts/"
---

# Laravel 13 Action Classes Example

_Published: July 24, 2026_  
_Author: Bharat Desai_  

![Laravel 13 Action Classes Example](https://magecomp.com/blog/wp-content/uploads/2026/07/Laravel-13-Action-Classes-Example-1024x512.webp)

Action Classes are used to keep controllers clean, as it helps in extracting logic to dedicated classes instead of cluttering controllers with logic. The usage of Reusable Action classes in an application helps in maintaining its maintainability, testability, and scalability.

In this article, we will present a simple example of Action Classes and demonstrate how the Action Classes can be used to create users.

[![Laravel Development Services](https://magecomp.com/blog/wp-content/uploads/2024/12/Laravel-Development-Services-3-1024x284.webp)](https://magecomp.com/services/laravel-development-services/)

## Steps for Laravel 13 Action Classes Example
Step 1: Install Laravel 13

Step 2: Create Migration and Model

Step 3: Configure Database

Step 4: Run Migration

Step 5: Create Action Class

Step 6: Create Controller

Step 7: Define Route

Step 8: Test the Application

Run Laravel App

### Step 1: Install Laravel 13
First, create a fresh Laravel 13 application using the following command:

```
composer create-project laravel/laravel action-class-app
```

Move to the project directory:

```
cd action-class-app
```

### Step 2: Create Migration and Model
Create the User model with a migration:

```
php artisan make:model User -m
```

Then, open the migration file and modify it:

**database/migrations/xxxx_xx_xx_create_users_table.php**

```
public function up(): void
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamps();
    });
}
```

### Step 3: Configure Database
Open the .env file and configure your database.

```
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=action_class
DB_USERNAME=root
DB_PASSWORD=
```

### Step 4: Run Migration
Execute the migration:

```
php artisan migrate
```

### Step 5: Create Action Class
Create an Action class in the app directory.

app/

└── Actions/

Create the action class:

**app/Actions/CreateUserAction.php**

```
<?php
namespace AppActions;
use AppModelsUser;
class CreateUserAction
{
    public function execute(array $data): User
    {
        return User::create([
            'name'  => $data['name'],
            'email' => $data['email'],
        ]);
    }
}
```

Update the User model.

**app/Models/User.php**

```
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
    protected $fillable = [
        'name',
        'email',
    ];
}
```

### Step 6: Create Controller
Create a controller.

```
php artisan make:controller UserController
```

Update the controller.

**app/Http/Controllers/UserController.php**

```
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppActionsCreateUserAction;
class UserController extends Controller
{
    public function store(Request $request, CreateUserAction $createUser)
    {
        $user = $createUser->execute($request->only([
            'name',
            'email'
        ]));
        return response()->json([
            'message' => 'User created successfully.',
            'user' => $user,
        ]);
    }
}
```

### Step 7: Define Route
Open the following file:

```
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersUserController;
Route::post('/users', [UserController::class, 'store']);
```

### Step 8: Test the Application
Start the Laravel development server.

```
php artisan serve
```

Send a POST request to:

http://127.0.0.1:8000/users

```
Request Body:
{
    "name": "John Doe",
    "email": "john@example.com"
}
```

**Output:**

```
{
    "message": "User created successfully.",
    "user": {
        "id": 1,
        "name": "John Doe",
        "email": "john@example.com",
        "created_at": "2026-07-24T10:15:20.000000Z",
        "updated_at": "2026-07-24T10:15:20.000000Z"
    }
}
```

Run Laravel App

```
php artisan serve
```

## Conclusion
In the above example, we have learned how to use Action Classes in Laravel 13 to keep the code separated from the controller while maintaining the code’s reusability. It keeps the controller clean and makes it easier to maintain and test the application as it grows.

[![Hire Laravel Developer](https://magecomp.com/blog/wp-content/uploads/2024/12/Hire-Laravel-Expert-Now-2-1024x284.webp)](https://magecomp.com/services/hire-laravel-developer/)

## FAQ
**1. Are Action Classes included in Laravel 13 by default?**

No, Action Classes are not included in Laravel 13 by default. These classes are a common architectural pattern used by developers to separate the business logic.

**2. Is there any difference between an Action class and a Controller class?**

Controller is responsible for the execution of the request, whereas Action Classes have the business logic that can be reused across multiple controllers or other jobs or commands.


---

_View the original post at: [https://magecomp.com/blog/laravel-13-action-classes/](https://magecomp.com/blog/laravel-13-action-classes/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-07-24 22:34:00 UTC_  
