Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/larapack/command-validation
Enable a method for Artisan Commands to validate the output of methods like `ask`.
https://github.com/larapack/command-validation
Last synced: about 2 months ago
JSON representation
Enable a method for Artisan Commands to validate the output of methods like `ask`.
- Host: GitHub
- URL: https://github.com/larapack/command-validation
- Owner: larapack
- License: mit
- Created: 2015-11-27T13:29:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-10T10:09:58.000Z (almost 8 years ago)
- Last Synced: 2024-09-18T14:57:55.710Z (4 months ago)
- Language: PHP
- Size: 22.5 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Laravel Command Validation
Enable a method for Artisan Commands to validate the output of methods like `ask`.## Installing
Install using composer `composer require "larapack/command-validation 1.*"`.
## Usage
First add the trait `Validateable` to your Artisan Command.
```
validate(function() {
// Here we ask the question we want and return the output
// Any method returning a value from the command line input can be used here.
return $this->ask('What is your age?', null);
}, function($value) {
// Here we validate the value
// If the value is NOT valid, we should return a error message.
// If the value is valid, we don't need to return anything.
// NOTE: Returning true will also be valid.
if (!is_numeric($value)) return "Age [{$value}] is not numeric.";
});
// Once we are here you will have the validage age
$this->info("So you are {$age} years old.");
}
```It will look like this:
![Command Line Example](https://raw.githubusercontent.com/larapack/command-validation/master/resources/command-line-example.png)