Prompt file imported from Korey90/agent-manager (
.github/prompts/laravel-action.prompt.md). Copyright stays with the author.
Laravel Action Implementation
Use this for any non-trivial business operation (CreateLead, GenerateInvoice, SendNotification, etc.).
Template
<?php
namespace App\Actions\{Module};
use App\Models\{Model};
use App\DataTransferObjects\{Model}Data;
final class {ActionName}Action
{
public function execute({Model}Data $data): {Model}
{
return DB::transaction(function () use ($data) {
$model = {Model}::create($data->toArray());
event(new {Model}Created($model));
return $model;
});
}
}
Steps
- Run delta-analysis first
- Create DTO if needed (
app/DataTransferObjects/) - Create Action class (
app/Actions/{Module}/) - Implement
execute()method with proper typing - Wrap in DB transaction if needed
- Fire events
- Call Action from thin controller or Job
- Write unit test for the Action