https://github.com/devlop/laravel-console-input-validation
A small trait to make it easier to validate the input to your Laravel commands.
https://github.com/devlop/laravel-console-input-validation
artisan laravel validation
Last synced: 18 days ago
JSON representation
A small trait to make it easier to validate the input to your Laravel commands.
- Host: GitHub
- URL: https://github.com/devlop/laravel-console-input-validation
- Owner: devlop
- License: mit
- Created: 2021-03-01T06:58:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-09-15T22:38:26.000Z (9 months ago)
- Last Synced: 2025-10-25T18:35:16.548Z (7 months ago)
- Topics: artisan, laravel, validation
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Console Input Validation
A small trait to make it easier to validate the input to your Laravel commands.
# Installation
```bash
composer require devlop/laravel-console-input-validation
```
# Usage
```php
use Devlop\Laravel\Console\ValidateInput;
use Symfony\Component\Console\Input\InputInterface;
class DemoCommand extends Command
{
use ValidateInput;
/**
* Validate the console command input.
*
* @throws InvalidArgumentException
*/
protected function validate(InputInterface $input) : void
{
// Example using manual validation
if (! is_numeric($input->getOption('limit'))) {
throw new InvalidArgumentException('--limit must be numeric');
}
// Example using webmozarts/assert
Assert::numeric($input->getOption('limit')); // assert that the --limit option got a numeric value
Assert::greaterThan($input->getOption('limit'), 0); // assert that the --limit option get a value greater than 0
}
public function handle() : int
{
// ...
}
}
```