Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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)