milwad / laravel-validate
The Laravel-Validate package enhanced Laravel validation capabilities with custom rules and methods for simplified and efficient validation logic.
Installs: 17 542
Dependents: 1
Suggesters: 0
Security: 0
Stars: 461
Watchers: 11
Forks: 39
Open Issues: 0
Requires
- php: ^8.0
- ext-bcmath: *
- ext-ctype: *
- laravel/framework: 9.*|10.*|11.*
Requires (Dev)
- imanghafoori/php-imports-analyzer: 1.0.*
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
README
The Laravel-Validate
package enhanced Laravel validation capabilities with custom rules and methods for simplified and efficient validation logic.
You can validate data more easily, Laravel validate has lots of rule classes for validation.
This package supports localization and can be used for most of the language.
(If some language didn't support, you can PR for new language)
Requirements
PHP >= 8.0
Laravel >= 9.0
Morilog-Jalali >= 3.x
Installation
You can install the package with Composer.
composer require milwad/laravel-validate
Publish
If you want to publish a lang file for a custom validation message you can run this command in the terminal:
php artisan vendor:publish --tag="validate-lang-{$lang}"
You can replace $lang
with your lang name, for ex:
php artisan vendor:publish --tag="validate-lang-en"
If you don't know about langs name you can go Support Languages
Usage
You can use Laravel-Validate Rules
very simply. You can use the new
keyword before the rule name.
use Milwad\LaravelValidate\Rules\ValidPhoneNumber; return [ 'phone' => ['required', new ValidPhoneNumber()], ];
Rules
Rules
ValidPattern
Sometimes you need to validate text with a pattern, For example, you want to validate a text like (4444-4444-4444).
If you want to check the length of the text is separate after -
is 4, You can use this Rule:
use Milwad\LaravelValidate\Rules\ValidPattern; return [ 'numbers' => ['required', new ValidPattern(4, '-')], ];
ValidIban
Sometimes you need to validate the Iban(International Bank Account Number) code. You can use the ValidIban
rule:
use Milwad\LaravelValidate\Rules\ValidIban; return [ 'iban' => ['required', new ValidIban()], // iban => SC74MCBL01031234567890123456USD ];
Also, you can use the Country
class to add a list of countries to the ValidIban
rule. By doing this your IBAN must belong
to one of the countries you pass to the validation class:
use Milwad\LaravelValidate\Rules\ValidIban; use Milwad\LaravelValidate\Utils\Country; return [ 'iban' => ['required', new ValidIban(Country::IRAN, Country::SEYCHELLES)], // iban => SC74MCBL01031234567890123456USD ];
Support Languages
If a language is not supported, you can make issue to add it.
Also, you can make PR to add it.
- Arabic (ar)
- Azerbaijani (az)
- Bangla (bn)
- Catalan (ca)
- German (de)
- Greek (el)
- English (en)
- Spanish (es)
- Persian (fa)
- French (fr)
- Hindi (hi)
- Indonesian (id)
- Italian (It)
- Japanese (ja)
- Korean (ko)
- Kurdish Sorani (ku_so)
- Português Brasil (pt_BR)
- Russian (ru)
- Sinhala (si)
- Swedish (sv)
- Turkish (tr)
- Ukrainian (uk)
- Chinese (zh_CN)
License
- This package is created and modified by Milwad Khosravi for Laravel over more than 9 and has been released under the MIT License.
Contributing
This project exists thanks to all the people who contribute. CONTRIBUTING
Security
If you've found a security bug, please email milwad.dev@gmail.com instead of using the issue tracker.
Star History
Donate
If this package is helpful for you, you can buy a coffee for me :) ❤️
- Iraninan Gateway: https://daramet.com/milwad_khosravi
- Paypal Gateway: SOON
- MetaMask Wallet:
0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58