# Commands

**Package:** Laravel Modules | **Version:** 3 | **URL:** https://mozex.dev/docs/laravel-modules/v3/features/commands

---

Artisan command classes inside modules are discovered and registered automatically. Any non-abstract class extending `Illuminate\Console\Command` that lives under a configured path becomes available in Artisan.

## Default configuration

```php
'commands' => [
    'active' => true,
    'patterns' => [
        '*/Console/Commands',
    ],
],
```

## Directory layout

```
Modules/Blog/
└── Console/
    └── Commands/
        ├── PublishPosts.php          // discovered (extends Command)
        ├── PruneDrafts.php           // discovered (extends Command)
        └── BaseCommand.php           // ignored (abstract class)
```

## Writing a module command

Module commands work exactly like application commands. Define a `$signature`, a `$description`, and a `handle()` method:

```php
namespace Modules\Blog\Console\Commands;

use Illuminate\Console\Command;

class PublishPosts extends Command
{
    protected $signature = 'blog:publish-posts
                            {--dry-run : Show what would be published without making changes}';

    protected $description = 'Publish all scheduled posts that are past their publish date';

    public function handle(): int
    {
        $query = Post::where('publish_at', '<=', now())
            ->where('status', 'draft');

        if ($this->option('dry-run')) {
            $this->info("Would publish {$query->count()} posts.");
            return self::SUCCESS;
        }

        $count = $query->update(['status' => 'published']);
        $this->info("Published {$count} posts.");

        return self::SUCCESS;
    }
}
```

Run it:

```bash
php artisan blog:publish-posts
php artisan blog:publish-posts --dry-run
```

## What gets discovered

The scanner finds all non-abstract classes that extend `Illuminate\Console\Command` (directly or through intermediate classes). Abstract base commands are skipped, so you can create shared base classes without them showing up in `php artisan list`.

## Signature collisions

Each command's `$signature` must be unique across your entire application, including all modules. If two modules register a command with the same signature, the second one overwrites the first. Use a module-specific prefix (like `blog:`, `shop:`) to avoid collisions.

## Console routes vs. command classes

You can also define closure-based Artisan commands in `Routes/console.php` files (see the [Routes](https://mozex.dev/docs/laravel-modules/v3/features/routes) docs). Use command classes when you want a dedicated class with its own tests and dependency injection. Use console routes for quick, one-off commands that don't need much structure.

## Disabling

Set `'commands.active' => false` to stop auto-registering module commands. Adjust `'commands.patterns'` if your modules use a different directory for commands.

---

## Table of Contents

- [Introduction](https://mozex.dev/docs/laravel-modules/v3)
- [AI Integration](https://mozex.dev/docs/laravel-modules/v3/ai-integration)
- [Support Us](https://mozex.dev/docs/laravel-modules/v3/support-us)
- [Requirements](https://mozex.dev/docs/laravel-modules/v3/requirements)
- [Changelog](https://mozex.dev/docs/laravel-modules/v3/changelog)
- [Contributing](https://mozex.dev/docs/laravel-modules/v3/contributing)
- [Questions & Issues](https://mozex.dev/docs/laravel-modules/v3/questions-and-issues)
- [About Mozex](https://mozex.dev/docs/laravel-modules/v3/about)

### Features

- [Blade Components](https://mozex.dev/docs/laravel-modules/v3/features/blade-components)
- [Views](https://mozex.dev/docs/laravel-modules/v3/features/views)
- [Routes](https://mozex.dev/docs/laravel-modules/v3/features/routes)
- [Configs](https://mozex.dev/docs/laravel-modules/v3/features/configs)
- [Migrations](https://mozex.dev/docs/laravel-modules/v3/features/migrations)
- [Seeders](https://mozex.dev/docs/laravel-modules/v3/features/seeders)
- [Commands](https://mozex.dev/docs/laravel-modules/v3/features/commands)
- [Helpers](https://mozex.dev/docs/laravel-modules/v3/features/helpers)
- [Models & Factories](https://mozex.dev/docs/laravel-modules/v3/features/models-factories)
- [Policies](https://mozex.dev/docs/laravel-modules/v3/features/policies)
- [Events & Listeners](https://mozex.dev/docs/laravel-modules/v3/features/events-listeners)
- [Service Providers](https://mozex.dev/docs/laravel-modules/v3/features/service-providers)
- [Translations](https://mozex.dev/docs/laravel-modules/v3/features/translations)
- [Caching](https://mozex.dev/docs/laravel-modules/v3/features/caching)
- [Listing Modules](https://mozex.dev/docs/laravel-modules/v3/features/listing)
- [Livewire Components](https://mozex.dev/docs/laravel-modules/v3/features/livewire-components)
- [Filament](https://mozex.dev/docs/laravel-modules/v3/features/filament)
- [Nova Resources](https://mozex.dev/docs/laravel-modules/v3/features/nova-resources)

### Integrations

- [PHPStan](https://mozex.dev/docs/laravel-modules/v3/integrations/phpstan)
- [PHPUnit](https://mozex.dev/docs/laravel-modules/v3/integrations/phpunit)
- [Pest](https://mozex.dev/docs/laravel-modules/v3/integrations/pest)
- [Inertia](https://mozex.dev/docs/laravel-modules/v3/integrations/inertia)