Download the PHP package perryvandermeer/laravel-console-validator without Composer

On this page you can find all versions of the php package perryvandermeer/laravel-console-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-console-validator

Validate arguments in Laravel commands

Latest Version on Packagist GitHub Pest Action Status GitHub Pint Status Total Downloads

This package allows you to easily validate all entered arguments in Laravel commands.

laravel-console-validator

Here's a brief example where we will automatically validate the foo argument against the required and min:3 rules:

Requirements

This package requires PHP 8.1+ and Laravel 10+.

Installation

You can install the package via composer:

Usage

To get started, you will need to include the ValidatesArguments trait in your command.
When the command is executed, it will automatically perform validation before reaching the handle() method. When the validation fails, the handle() method will never be executed.

Configuring The Validator

Just like when you use Laravel's validator, it is possible to configure the rules, messages and attributes.

Rules

You may configure the validation rules used by the command by defining the $rules property and/or the rules() method.

The rules() method can be helpful if you are trying to use run-time syntaxes that aren't supported in array properties, like Laravel rule objects such as Rule::password(). When you use both the $rules property and the rules() method, we merge them together.

The property and/or method should return an array of argument / rule pairs and their corresponding validation rules.

Messages

You may customize the error messages used by the command by defining the $messages property and/or the messages() method.

The messages() method can be helpful if you are trying to use run-time syntaxes that aren't supported in array properties. When you use both the $messages property and the messages() method, we merge them together.

The property and/or method should return an array of argument / rule pairs and their corresponding error messages.

Attributes

Many of Laravel's built-in validation rule error messages contain an :attribute placeholder. As default, the name of the argument is used as :attribute. If you would like the :attribute placeholder of your validation message to be replaced with a custom attribute name, you may specify the custom names by defining the $attributes property and/or the attributes() method..

The attributes() method can be helpful if you are trying to use run-time syntaxes that aren't supported in array properties. When you use both the $attributes property and the attributes() method, we merge them together.

The property and/or method should return an array of argument / name pairs.

Preparing Arguments For Validation

If you need to prepare or sanitize any data before you apply your validation rules, you may use the prepareForValidation() method.

Working With Validated Arguments

Just like when you use Laravel's validator, it is possible to use the validated arguments in the rest of your implementation.

Retrieving All Validated Arguments

After validating the arguments, you may wish to retrieve the arguments that actually underwent validation. This can be accomplished in several ways. First, you may call the validated() method within your command. This method returns an array of the data that was validated.

When you want a Collection of all arguments that underwent validation, you may call the collect() method within your command. This method returns a Collection of the data that was validated.

Retrieving A Single Validated Argument

When you pass an argument to the validated() method, it will only return the validated value of that argument. When the requested argument has not been validated, it will throw the UnvalidatedArgumentException exception.

When you want to make sure the validated value of the argument is cast to a string, you may use the string() method.

Your command may receive "truthy" values that are actually strings, like (string) 'true' or (string) 'on'. You may use the bool() or boolean() method to retrieve these values as booleans. Those methods use PHP's FILTER_VALIDATE_BOOLEAN flag to determine if the passed argument is (bool) true or (bool) false.

Testing

When using laravel/framework above version 11.9.0, you may use the custom assertFailedWithValidationError() method to assert that the command returned any validation error:

When using a lower version of laravel/framework, you may use the assertExitCode() method to assert that the command returned any validation error:

In addition, it may be useful to test for a specific validation error. You may use the expectsOutput() method to assert that the command returned a specific validation error:

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-console-validator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version ^10.0||^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package perryvandermeer/laravel-console-validator contains the following files

Loading the files please wait ....