cerbero / command-validator
Laravel package to validate the input of console commands.
Installs: 300 984
Dependents: 1
Suggesters: 0
Security: 0
Stars: 220
Watchers: 6
Forks: 13
Open Issues: 0
Requires
- php: ^8.2
- illuminate/contracts: >=11.0
- symfony/console: ^7.0
Requires (Dev)
- orchestra/testbench: >=9.0
- pestphp/pest: ^3.0
- phpstan/phpstan: ^1.9
- squizlabs/php_codesniffer: ^3.0
- tightenco/duster: ^2.0
- uma/ocular: ^2.0
README
Laravel package to validate the input of console commands.
๐ฆ Install
Via Composer:
composer require cerbero/command-validator
๐ฎ Usage
To validate the input of our console commands, we can use the ValidatesInput
trait and define the validation rules for our arguments and options in the rules()
method:
use Illuminate\Console\Command; use Cerbero\CommandValidator\ValidatesInput; class SampleCommand extends Command { use ValidatesInput; protected function rules(): array { return [ 'some_argument' => 'integer|digits:4|min:2000', 'some_option' => 'string|max:2', ]; } }
The available rules are the same validation rules provided by Laravel. If we need custom validation, here is how we can define custom rules in Laravel.
Sometimes we may need to show custom messages or attributes for some validation errors. We can achieve that by overriding the methods messages()
and attributes()
:
protected function messages(): array { return [ 'min' => 'The minimum allowed :attribute is :min', ]; } protected function attributes(): array { return [ 'year' => 'year of birth', ]; }
๐ Change log
Please see CHANGELOG for more information on what has changed recently.
๐งช Testing
composer test
๐ Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
๐งฏ Security
If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.
๐ Credits
โ๏ธ License
The MIT License (MIT). Please see License File for more information.