laracraft-tech/laravel-schema-rules
Generate baseline Laravel validation rules from your database schema. Create rules for entire tables or selected columns, generate Form Request classes, and configure columns to always skip. Works across supported drivers and serves as a solid starting point for custom validation.
StoreXRequest/UpdateXRequest classes, reducing repetitive boilerplate in API/controller layers.skip_columns config: Exclude columns (e.g., deleted_at, created_at) globally.jsonb, SQLite’s length limits).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Rule Accuracy | Generated rules may not cover all edge cases (e.g., float/decimal precision, complex enum validation, or custom constraints). |
Validation: Manually audit generated rules for critical tables. Use as a starting point, not a replacement for business logic. |
| Database Driver Gaps | Some drivers (e.g., SQLite) have limited type support (e.g., no float rules). PostgreSQL’s jsonb is supported but may lack nuanced validation. |
Fallback: Document unsupported types and implement custom rules where needed. Monitor for updates (e.g., float support in future releases). |
| Migration Dependence | Rules are schema-dependent; breaking migrations could invalidate generated rules. | CI/CD Check: Add a pre-deploy validation step to regenerate rules after migrations. Use feature flags for critical validations during transitions. |
| Performance | Schema inspection at runtime may introduce minor overhead during rule generation (though negligible in development). | Cache Rules: Store generated rules in config/cache for reuse across requests (e.g., via a service provider). |
| Form Request Conflicts | Auto-generating Form Requests could overwrite existing files if not careful. | Safety Flags: Use --force judiciously. Prefer partial generation (e.g., only rules) or manual merging for existing requests. |
| Laravel Version Lock | Supports Laravel 11–13 but may lag behind minor versions (e.g., 10.35+ fixes). | Dependency Pinning: Lock to a specific minor version (e.g., ^12.0) in composer.json to avoid surprises. Monitor for breaking changes. |
Validation Strategy:
Workflow Integration:
Database Diversity:
jsonb with nested validation) that require custom solutions?Maintenance:
Testing:
| Phase | Action | Tools/Strategies |
|---|---|---|
| Assessment | Audit existing validation rules to identify redundancy and schema mismatches. | Static Analysis: Use phpstan to detect unused validation rules. Manual Review: Compare critical rules against generated output. |
| Pilot | Generate rules for non-critical tables (e.g., users, posts) and compare outputs with existing validation. |
Feature Flag: Wrap generated rules in a feature flag (e.g., config('validation.use_schema_rules')) for gradual rollout. |
| Incremental Rollout | Replace manual rules table-by-table, starting with high-maintenance or frequently updated schemas. | CI Check: Add a pre-commit hook to regenerate rules for modified tables. Git Diff: Review changes to Form Requests. |
| Full Adoption | Enable auto-generation for all tables, with manual overrides for exceptions. | Custom Provider: Register a service provider to cache rules and preload Form Requests. Documentation: Update team on override conventions. |
| Optimization | Fine-tune rules for performance-critical paths (e.g., caching, lazy validation). | Benchmark: Profile validation overhead with laravel-debugbar. Custom Rules: Implement Rule objects for complex logic. |
float, jsonb) may require manual handling.spatie/laravel-permission). Test with auth/role-based validation tools.array, custom enum) will skip generation; document these as known gaps.composer require --dev).php artisan vendor:publish --tag="schema-rules-config").skip_columns (e.g., ['deleted_at', 'created_at', 'custom_skip']).php artisan schema:generate-rules --all if supported).php artisan schema:generate-rules users --create-request).users, payments).How can I help you explore Laravel packages today?