Download the PHP package bakome/laravel-validation-attributes without Composer
On this page you can find all versions of the php package bakome/laravel-validation-attributes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-validation-attributes
Use PHP 8 attributes to implement request data validation
This package provides annotations to easily add validation rules on action methods in a controller. Here's a quick example:
Motivation
This project exists to provide simple and cleaner way to validate request data on Laravel controllers. Using validation rules in action methods often complicate readability of the controller and adding validation in separate requests classes imply switching trough that classes multiple time to view and change the rules (Losing focus). With this simple attributes we can make validation more accessible and maintainable in the controllers without messing the controller code.
Installation
You can install the package via composer:
You can publish the config file with:
Usage
The package provides several annotations that should be put on controller action methods. These annotations are used to validate request data.
Adding a validation rule with string as a parameter
This attribute will check if title parameter is present in current request and throw validation error if not present.
Adding a validation rule with an array as a parameter
This attribute will check if title parameter is present in current request and throw validation error if not present.
Adding a multiple validation rules
This attribute will check if title and description parameters are present in current request and throw validation error if not present.
Adding a redirect for failed validation
This attribute will check if title and description parameters are present in current request, compile validation error messages and redirect the page to provided route.
Adding a redirect with input for failed validation
This attribute will check if title and description parameters are present in current request, compile validation error messages and redirect the page to provided route including old input parameters.
Ajax's requests awareness and proper json responses returned for failed validation
Config
Plugin enabled/disabled
This plugin can be enabled or disabled with altering this property in configuration file. Default value is true (Enabled).
Plugin enabled/disabled
This property enables developers to provide a different handler for Validation via Middleware. Please be careful with this option and don't change it if you don't need custom behaviour.
Validation middleware
This property enables developers to provide a different handler for Validation via Middleware. Please be careful with this option and don't change it if you don't need custom behaviour.
Detect api routes
This property provide value for detecting api routes. Using expects json sometimes is not enough and when that lacks this option/feature do the job.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
Roadmap
- Provide custom validation messages
- Provide validation groups to reduce boilerplate code