New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

cerbero/command-validator

Laravel package to validate the input of console commands.
525,605 223
Install
composer require cerbero/command-validator
Latest Version:3.0.0
PHP:^8.2
Laravel:11
Older releases:5 – 8
License:MIT
Last Updated:Sep 12, 2024
Links: GitHub  ·  Packagist
Maintainer: cerbero

✅ Command Validator

Author PHP Version Laravel Version Build Status Coverage Status Quality Score PHPStan Level Latest Version Software License PER Total Downloads

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.

Related Packages

rahul900day/laravel-console-spinner

Laravel Console Spinner is a spinner output for Laravel command line.

136,079 76
jdsantos/laradocker

A Laravel package to seamlessly integrate Docker into your application

1,609 6
nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2,677,473 260
nunomaduro/laravel-console-summary

A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.

2,616,282 67
nunomaduro/laravel-console-menu

Laravel Console Menu is an output method for your Laravel/Laravel Zero commands.

459,356 810

Version History

Version Released PHP Laravel License
3.0.0 ^8.2 >=11.0 MIT
2.5.0 ^7.0||^8.0 >=5.5 MIT
2.4.1 ^7.0||^8.0 >=5.5 MIT
2.4.0 ^7.0||^8.0 >=5.5 MIT
2.3.0 ^7.0.8 ^5.5|^6.0|^7.0|^8.0 MIT