cerbero90 / command-validator by cerbero

Validate Laravel console commands input.
302,593
221
6
Package Data
Maintainer Username: cerbero
Maintainer Contact: andrea.marco.sartori@gmail.com (Andrea Marco Sartori)
Package Create Date: 2016-04-05
Package Last Update: 2024-09-12
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:12:02
Package Statistics
Total Downloads: 302,593
Monthly Downloads: 8,499
Daily Downloads: 449
Total Stars: 221
Total Watchers: 6
Total Forks: 13
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.