laraditz/action
Define single-purpose Action classes for Laravel and Lumen to keep code DRY. Generate actions via artisan, pass data through constructor properties, and execute with handle() or a convenient static run() method. Includes a data() helper for all properties.
ActionServiceProvider) provide.HandleRequests trait), which could be a limitation for authenticated/authorized actions.make:action) integrates smoothly with Laravel’s scaffolding ecosystem.FormRequest or Validator) unless integrated separately.action:before, action:after).try-catch blocks or using Laravel’s ValidatesRequests).handle() returning a response object).CreatePost action).php artisan make:action for new features; refactor existing logic into actions incrementally.use App\Actions\CreateNewPost;
$action = new CreateNewPost($request->title, $request->body);
$action->handle();
Action class to add shared behavior (e.g., validation, logging).namespace App\Actions;
use Laraditz\Action\Action;
use Illuminate\Support\Facades\Log;
abstract class BaseAction extends Action {
public function handle(): mixed {
Log::info("Action executed: " . static::class);
return parent::handle();
}
}
composer require laraditz/action
php artisan make:action CreateUser
// Before
public function store(Request $request) {
return Post::create($request->all());
}
// After
public function store(Request $request) {
$action = new CreateNewPost(
title: $request->title,
body: $request->body
);
return $action->handle();
}
App\Actions).try-catch or Laravel’s app()->abort().UserActions, OrderActions).ClassNotFound errors.DB::transaction() within actions.How can I help you explore Laravel packages today?