2017 © Pedro Peláez
 

package command-validation

Enable a method for Artisan Commands to validate the output of methods like `ask`.

image

larapack/command-validation

Enable a method for Artisan Commands to validate the output of methods like `ask`.

  • Friday, February 10, 2017
  • by marktopper
  • Repository
  • 1 Watchers
  • 5 Stars
  • 67 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

Laravel Command Validation

Enable a method for Artisan Commands to validate the output of methods like ask., (*1)

Installing

Install using composer composer require "larapack/command-validation 1.*"., (*2)

Usage

First add the trait Validateable to your Artisan Command., (*3)

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Larapack\CommandValidation\Validateable;

class ExampleCommand extends Command
{
  use Validateable;

  // ...
}

Then use the validate-method:, (*4)

  public function fire()
  {
    // We want to get the age from the user, but we would like to validate it.
    // So we use the validate method.
    $age = $this->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:, (*5)

Command Line Example, (*6)

The Versions

10/02 2017

dev-master

9999999-dev

Enable a method for Artisan Commands to validate the output of methods like `ask`.

  Sources   Download

MIT

laravel command validation validate artisan package larapack

13/01 2017

v1.x-dev

1.9999999.9999999.9999999-dev

Enable a method for Artisan Commands to validate the output of methods like `ask`.

  Sources   Download

MIT

laravel command validation validate artisan package larapack

13/01 2017

dev-develop

dev-develop

Enable a method for Artisan Commands to validate the output of methods like `ask`.

  Sources   Download

MIT

laravel command validation validate artisan package larapack

27/11 2015

v1.0.0

1.0.0.0

Enable a method for Artisan Commands to validate the output of methods like `ask`.

  Sources   Download

MIT

laravel command validation validate artisan package larapack