Skip to content

Action classes

An action is a PHP class that describes an HTTP operation. Start with Exert\Action, then add a public handle() method.

php
<?php

namespace App\Http\Actions\System;

use Exert\Action;

class Status extends Action
{
    public function handle(): array
    {
        return ['status' => 'ok'];
    }
}

This is a complete action. It inherits GET as its allowed method, no action middleware, and disabled Precognition.

The four parts you can define

PartPurposeBase default
$methodsAllowed HTTP methods['GET']
middleware()Checks around this actionAn empty array
$precognitionEnable action-level predictionfalse
handle()Perform the operation and return its resultYou must define it

The handler may take a request, a form request, or services. It may return an array, a response, or another value Laravel can turn into a response. You do not need a fixed handler signature.

Generated actions have one different default

make:action explicitly writes $precognition = true in its template. That is different from the base class. Choose the value you need rather than assuming the generated file has no behavior to review.

Name the work

Names such as CancelOrder, SendInvitation, and PublishArticle describe a specific operation. A name such as ManageOrder usually leaves too much work for one class.

Keep the HTTP concerns here: input, permissions, calling services, and choosing the response. Move business logic to a service when it grows or must be shared with a job or command.

A class is not an endpoint yet

Exert does not scan your action directory and expose everything it finds. The controller's map decides which names are available. The route decides where the controller is reachable.

That explicit chain is useful when you need to answer: “Can a client call this operation?”

Continue with: Controllers and registration, HTTP methods, or Dependency injection.

An opinionated Laravel package. Released under the MIT license.