Download the PHP package denizgolbas/laravel-equality-validation without Composer
On this page you can find all versions of the php package denizgolbas/laravel-equality-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download denizgolbas/laravel-equality-validation
More information about denizgolbas/laravel-equality-validation
Files in denizgolbas/laravel-equality-validation
Package laravel-equality-validation
Short Description A powerful Laravel validation rule for checking equality between reference and target model columns. Perfect for validating relationships, matching codes, currencies, and ensuring data consistency across related models.
License MIT
Homepage https://github.com/denizgolbas/laravel-equality-validation
Informations about the package laravel-equality-validation
Laravel Equality Validation
A powerful Laravel validation rule for checking equality between reference and target model columns. Perfect for validating relationships, matching codes, currencies, and ensuring data consistency across related models.
Installation
You can install the package via Composer:
The package will automatically register its service provider.
Configuration
You can publish the config file with:
Usage
This validation rule allows you to validate that a column value from a reference model matches a column value from a target model.
Example 1: Basic Request Validation
Example 2: Using FormRequest Class
Example 3: Validating Warehouse and Product Location
Example 4: Validating Multiple Items in Array
Example 5: Validating User and Company Relationship
Example 6: Validating Nested Data Structure
Example 7: Using Helper Method (Alternative Syntax)
Parameters
The EqualityValidationRule constructor accepts the following parameters:
$referenceModel(string): The fully qualified class name of the reference model$referenceColumn(string): The column name in the reference model to compare$targetModel(string): The fully qualified class name of the target model$targetColumn(string): The column name in the target model to compare$targetAttribute(string): The attribute name in the request that contains the target model ID$sameLine(bool, optional): Whether to use the same line/level for finding the target attribute. Defaults totrue
Same Line Parameter
When $sameLine is true (default), the rule will look for the target attribute at the same nesting level as the reference attribute. For example:
When $sameLine is false, it will use the base attribute name:
Example 8: Real-World E-Commerce Scenario
Example 9: Validating with Different Column Names
Translation
The package includes English and Turkish translations. You can publish the language files to customize the error messages:
This will publish the language files to lang/vendor/equality-validation/{locale}/validation.php.
After publishing, you can customize the error messages in the published files.
The default error message is:
English:
The :reference_column of :reference_model does not match the :target_column of :target_model.
Turkish:
:reference_model'in :reference_column değeri, :target_model'in :target_column değeri ile eşleşmiyor.
If you want to use the translations in your application's main language files instead, you can copy the validation key to your lang/{locale}/validation.php file under the custom key.
Testing
License
The MIT License (MIT). Please see License File for more information.
Author
Deniz Golbas - [email protected]
All versions of laravel-equality-validation with dependencies
illuminate/contracts Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
illuminate/validation Version ^10.0|^11.0