← Laractions 11 / 12

Artisan commands

Two commands ship with the package, both registered only when Laravel runs in the console.

make:action

php artisan make:action SendWelcomeEmail
php artisan make:action SendWelcomeEmail --model=User
php artisan make:action Billing/RetryPayment
Signature make:action {name} {--model=}
Without --model App\Actions\{Name} in app/Actions/{Name}.php
With --model App\Actions\{Model}\{Name} in app/Actions/{Model}/{Name}.php

A name with slashes nests inside app/Actions, so Billing/RetryPayment becomes App\Actions\Billing\RetryPayment. With --model the nesting is dropped: the model decides the folder, and only the last segment of the name is used as the class.

--model takes a short name or a fully qualified one. A short name is assumed to live in App\Models, so --model=User and --model="App\Models\User" are the same thing, while --model="App\Domain\Billing\Invoice" imports that class and still writes to app/Actions/Invoice/.

The model stub declares the typed property for you, which is the only wiring a model action needs:

namespace App\Actions\User;

use EduLazaro\Laractions\Action;
use App\Models\User;

class SendWelcomeEmail extends Action
{
    protected User $user;

    public function handle()
    {
        // Implement action logic for user here
    }
}

The name is used exactly as given: nothing strips a trailing Action, so keeping the convention is up to you. See Creating actions.

list:actions

php artisan list:actions
Available Actions:
- App\Actions\SendWelcomeEmail
- App\Actions\Billing\RetryPayment
- App\Actions\User\AnonymizeUser

It walks app/Actions recursively and turns each file path into a class name. That is worth knowing for what it implies: it lists files in that folder, not classes that extend Action. An action written somewhere else does not appear, and a file in there that is not an action does. It is an inventory of the convention, not a registry, and there is nothing to register anywhere.

If the folder does not exist yet, the command says so and exits.