Skip to content

env:encrypt command not working when added macro on Illuminate\Console\Scheduling\Event in AppServiceProvider::boot method #50716

Closed
@pecqueurS

Description

@pecqueurS

Laravel Version

11.0.8

PHP Version

8.3

Database Driver & Version

not needed

Description

env:encrypt command not working when added macro on Illuminate\Console\Scheduling\Event in AppServiceProvider::boot method.

Others commands work as expected , but not env:encrypt.

output :

BadMethodCallException 
Method Illuminate\Console\Scheduling\Event::custom does not exist.
at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:112

This command does not load Providers boot method and not load Macros defined inside.

Steps To Reproduce

AppServiceProvider:

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Event::macro('custom', function() {
            return $this
            ->onOneServer()
            ->runInBackground();
        });
    }

providers.php:

return [
    App\Providers\AppServiceProvider::class,
];

console.php:

// use macro
Schedule::command('sanctum:prune-expired --hours=24')->daily()->custom();

launch command :

php artisan env:encrypt --help

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions