Skip to content

regnerisch/laravel-command-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Command Hooks

This package adds a before and after hook to Laravels command class.

Usage

The methods are only called if they are defined inside you class. If you do not need them, do not implement them. Returning a none zero value inside you before method will exit the execution immediately. Neither handle/ __invoke nor the after method will be called. The after method will get the exit code of the executed handle/ __invoke method, you can manipulate the exit code inside the after method and overwrite it by returning you own exit code. Returning null or nothing will keep the original exit code.

use \Regnerisch\LaravelCommandHooks\Command;

class MyCustomCommand extends Command
{
    protected function before(): ?int
    {
        // Do something before the command
        
        return $code;
    }
    
    protected function after(int $code): ?int
    {
        // Do something after the command
        
        return $code;
    }
    
    // ...
}

Contributors

License

ISC

About

This package adds a before & after hook on Laravels command class

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages