.cursor/skills/laravel-actions/references/command.md
asCommand)Use this reference when exposing actions as Artisan commands.
asCommand(...) and fallback to handle(...).$commandSignature and $commandDescription.asCommand(Command $command) for console I/O.handle(...).CommandDecorator)asCommandCalled when executed as a command. If missing, it falls back to handle(...).
use Illuminate\Console\Command;
class UpdateUserRole
{
use AsAction;
public string $commandSignature = 'users:update-role {user_id} {role}';
public function handle(User $user, string $newRole): void
{
$user->update(['role' => $newRole]);
}
public function asCommand(Command $command): void
{
$this->handle(
User::findOrFail($command->argument('user_id')),
$command->argument('role')
);
$command->info('Done!');
}
}
getCommandSignatureDefines the command signature. Required when registering an action as a command if no $commandSignature property is set.
public function getCommandSignature(): string
{
return 'users:update-role {user_id} {role}';
}
$commandSignatureProperty alternative to getCommandSignature.
public string $commandSignature = 'users:update-role {user_id} {role}';
getCommandDescriptionProvides command description.
public function getCommandDescription(): string
{
return 'Updates the role of a given user.';
}
$commandDescriptionProperty alternative to getCommandDescription.
public string $commandDescription = 'Updates the role of a given user.';
getCommandHelpProvides additional help text shown with --help.
public function getCommandHelp(): string
{
return 'My help message.';
}
$commandHelpProperty alternative to getCommandHelp.
public string $commandHelp = 'My help message.';
isCommandHiddenDefines whether command should be hidden from artisan list. Default is false.
public function isCommandHidden(): bool
{
return true;
}
$commandHiddenProperty alternative to isCommandHidden.
public bool $commandHidden = true;
// app/Console/Kernel.php
protected $commands = [
UpdateUserRole::class,
];
$this->artisan('users:update-role 1 admin')
->expectsOutput('Done!')
->assertSuccessful();
use Illuminate\Console\Command; is imported.handle(...).