What are Laravel Action Classes and How to use them?

Reza Khademi
3 min readAug 13, 2022


What are Laravel Action Classes and How to use them?

Recently, Action Classes became more popular and more developers convinced to use them.

In fact, Laravel Action classes are mini services which we use to separate any action from each others (just as Single Responsibility Principle).

Actions will try to make code cleaner and simpler and when you have a web-app that is becoming bigger and bigger action classes can help you to develop system easier!

There are a couple of packages to use action classes on Laravel but to be honest, we don’t necessarily need them and a well structured implement will do same thing even better!

Imagine we want to create a very simple system that a user can register, login and have a profile. In this case we should develop an action for each system act.

List of possible actions for this scenario:

  1. RegisterNewUser
  2. LoginUser
  3. UpdateUserPassword
  4. UpdateUserProfile

First of all we will create an action folder in app directory and for each act we will make a separate class:

  1. RegisterNewUser

We will create an action class:

  • app/Actions/RegisterNewUser.php

Then related controller:

  • php artisan make:controller UserRegisterController

Let’s write store method on UserRegisterController and for request validation we should create a specified request type so we run this artisan command:

php artisan make:request StoreUserRequest

After that on UserRegisterController : (RegisterNewUser is our action class)

Laravel Action classes

And any action class should have a handle() function to implement related logic like this:

Laravel action class

Well, that’s it for our first action.

Let’s do one more to understand it better.

2. UpdateUserPassword

We will create Action , Controller and proper Request:

  • app/Actions/UpdateUserPassword.php
  • php artisan make:controller ForgotPasswordController
  • php artisan make:request UserForgotPasswordRequest

On this controller we have:

So on, action class will be: