cerbero90 / command-validator by cerbero

Validate Laravel console commands input.
247,652
160
5
Package Data
Maintainer Username: cerbero
Maintainer Contact: andrea.marco.sartori@gmail.com (Andrea Marco Sartori)
Package Create Date: 2016-04-05
Package Last Update: 2021-08-09
Language: PHP
License: MIT
Last Refreshed: 2024-04-17 15:13:33
Package Statistics
Total Downloads: 247,652
Monthly Downloads: 8,278
Daily Downloads: 464
Total Stars: 160
Total Watchers: 5
Total Forks: 11
Total Open Issues: 0

Command Validator

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

SensioLabsInsight

Laravel package to validate input in Artisan console commands.

Install

Via Composer

$ composer require cerbero/command-validator

Usage

This package merely consists in the ValidatesInput trait that Artisan commands can use to define their validation rules via the rules() method:

use Illuminate\Console\Command;
use Cerbero\CommandValidator\ValidatesInput;

class SampleCommand extends Command
{
    use ValidatesInput;

    public function rules()
    {
        return [
            'year' => 'integer|digits:4|min:2000'
        ];
    }
}

Both arguments and options can be validated with the rules provided by Laravel. If you need custom validation, please have a look at how to define custom rules.

Sometimes you may need to show custom messages or attributes for some validation errors, you can achieve that by overriding the methods messages() and attributes():

public function messages()
{
    return [
        'min' => 'The minimum allowed :attribute is :min'
    ];
}

public function attributes()
{
    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.