Download the PHP package hasan-22/generate_validation without Composer
On this page you can find all versions of the php package hasan-22/generate_validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hasan-22/generate_validation
More information about hasan-22/generate_validation
Files in hasan-22/generate_validation
Package generate_validation
Short Description A Laravel package to automatically generate validation rules from models.
License MIT
Homepage https://github.com/HASSAN-22/generate_validation
Informations about the package generate_validation
Generate validation 📝
A Laravel package to automatically generate validation rules from models.
✨ Features
- Generate Rules Automatically: Creates comprehensive validation rules for your models based on their database schema.
- Separate Store & Update Rules: Generates distinct rule sets for
store(create) andupdateoperations, handling nuances likerequiredvs.nullablefields. - Ignore Specific Columns: Skip certain columns when generating validation rules by passing them as an argument to the Artisan command.
- Override with Custom Rules: Define your own validation rules for specific models and columns in the configuration file, overriding the default auto-generated ones.
🚀 Installation
You can install the package via Composer:
📖 Usage
1. Generating a Form Request
-
First, create the migration.
-
Then, create the model.
-
Finally, run the Artisan command.
For example, we want to generate validation for the Post model.
First, create the migration and model using this command:
This is our Post migration
This is our Post model
And now run this command for generate the validations:
Note: Note: The id column is always excluded from generated validation rules.
Note: This will create a new file at app/Http/Requests/PostRequest.php containing the generated rules.
This is the PostRequest.php file
Note: Please review the created validation once to ensure that nothing is missing or excessive, and fix it if necessary.
2. Using the Form Request
You can now use this Form Request in your controller methods to automatically validate incoming requests.
⚙️ Configuration (Optional)
🎯 Custom Rules via Config
In addition to automatically generating rules based on your model's database schema, you can define custom validation rules for specific models and columns in the configuration file.
This allows you to override the auto-generated rules and fully control the validation logic.
1. Publish the Config File
If you haven't already published the config file, run:
This will create a file at: config/generate_validation.php
2. Define Your Custom Rules
3. How It Works
If a column has a custom rule defined in the config, the package will use that instead of generating the rule automatically.
If a column is not defined in custom_rules, the default auto-generation logic will be applied.
This gives you the flexibility to handle special cases without losing the convenience of automatic generation.
🖼 Blob & File Rules
You can customize the default rules for specific strategies. For example, to change the default max size for images, you can use the static methods of the BlobRuleGenerator class.
In your ServiceProvider's boot method:
💖 Support the Project
If you like this project and want to support its development, you can donate here: Donate via NOWPayments
🤝 Contributing
We welcome contributions! If you find a bug or have a suggestion for a new feature, please open an issue or submit a pull request on GitHub.
📄 License
generate_validation is open-sourced software licensed under the MIT license.