Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/setnemo/autogenerated-messages
Trait for customizing and auto-generate default messages by type for Laravel Validation
https://github.com/setnemo/autogenerated-messages
hacktobefest hacktoberfest-accepted laravel laravel-package laravel-validation laravel-validation-message
Last synced: about 1 month ago
JSON representation
Trait for customizing and auto-generate default messages by type for Laravel Validation
- Host: GitHub
- URL: https://github.com/setnemo/autogenerated-messages
- Owner: setnemo
- License: mit
- Created: 2021-10-05T09:21:31.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-07T08:43:01.000Z (3 months ago)
- Last Synced: 2024-11-13T06:52:36.325Z (about 1 month ago)
- Topics: hacktobefest, hacktoberfest-accepted, laravel, laravel-package, laravel-validation, laravel-validation-message
- Language: PHP
- Homepage: https://packagist.org/packages/setnemo/autogenerated-messages
- Size: 67.4 KB
- Stars: 4
- Watchers: 1
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Auto-generated default messages for Laravel Validation
This project will help to generate automatically error messages based on your validation rules in the Laravel project.
## How it works?
You install the package:
```bash
composer require setnemo/autogenerated-messages
```Then, in your Request class (which inherits from FormRequest), add the trait:
```php
'required|string|max:120',
'start_date' => 'required|integer',
'price' => 'nullable|numeric|min:0 ',
'pay_link' => 'nullable|string|url|max:256',
'video' => 'nullable|mimes:mp4,mov,avi',
'confidentiality' => 'required|string|in:public,personal',
];
}
}
```
It's all! Error messages will be generated based on your rules.Example:
```php
message());
```Result:
```php
[
'name.required' => 'name is required',
'name.string' => 'Value for name must be string',
'name.max' => 'Maximal value for name is 120',
'start_date.required' => 'start_date is required',
'start_date.integer' => 'Value for start_date must be integer',
'price.numeric' => 'Key price must be numeric',
'price.min' => 'Minimal value for price is 0',
'pay_link.string' => 'Value for pay_link must be string',
'pay_link.url' => 'Key pay_link must be valid url',
'pay_link.max' => 'Maximal value for pay_link is 256',
'video.mimes' => 'Allowed formats for video: mp4, mov, avi',
'confidentiality.required' => 'confidentiality is required',
'confidentiality.string' => 'Value for confidentiality must be string',
'confidentiality.in' => 'Allowed values for confidentiality: public, personal',
];
```## Supported types
Right now project supported next validation types:
```php
[
'required',
'integer',
'numeric',
'string',
'url',
'in',
'not_in',
'min',
'max',
'mimes',
'email',
'unique',
'json',
'image',
'accepted',
'array',
'boolean',
'regex',
'exists',
'uuid',
'after',
'ip',
'ipv4',
'ipv6',
'mac_address',
'starts_with',
'ends_with',
'doesnt_start_with',
'doesnt_end_with',
'multiple_of',
'same'
];
```Also, you can add another Laravel Validation types, just create fork this project and create pull request.
Or add in your project:
```php
addRuleNames(['test_rule']);
$this->addRulesToMessages(['test_rule' => 'test_message']);
```## Contributing Guide
> Please check [Contributing Guide](CONTRIBUTING.md)