Throughout this course, we've been extracting logic from the Controller into Services, Actions, Jobs, and Events. But why did we do all that? Just to make the Controller shorter?
No. The real payoff is reusability. Once your business logic lives in a Service or Action class, it can be called from anywhere — not just Controllers.
Let's demonstrate this with a real example: the same CreateUserAction we built earlier, reused across four different entry points.
1. From a Controller (Web or API)
This is what we've been doing throughout the course:
class UserController extends Controller{ public function store(StoreUserRequest $request, CreateUserAction $action) { $user = $action->execute($request->validated()); return response()->json(['data' => $user], 201); }}
Nothing new here. But now let's look at the same Action used elsewhere.
2. From an Artisan Command
Imagine you need to create users via the command line — for seeding, for admin scripts, or for importing from a CSV file.
php artisan make:command CreateUserCommand
app/Console/Commands/CreateUserCommand.php:
use App\Actions\CreateUserAction; class CreateUserCommand extends Command{ protected $signature = 'users:create {name} {email} {password}'; protected $description = 'Create a new user from the command line'; public function handle(CreateUserAction $action) { $user = $action->execute([ 'name' => $this->argument('name'), 'email' => $this->argument('email'), 'password' => bcrypt($this->argument('password')), 'roles' => [], ]); $this->info("User {$user->name} created successfully."); }}
The Action doesn't care who called it. It just receives data and creates