Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Schema Rules Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Schema-Driven Validation: Aligns perfectly with Laravel’s database-first approach, reducing manual validation rule maintenance. Ideal for projects where schema changes are frequent or validation rules must stay tightly coupled to the database structure.
  • Separation of Concerns: Generates boilerplate validation rules while allowing manual overrides, adhering to Laravel’s Form Request pattern and DRY (Don’t Repeat Yourself) principles.
  • Extensibility: Supports custom column exclusions, database-agnostic rule generation (MySQL, PostgreSQL, SQLite), and form request class generation, making it adaptable to complex validation needs.
  • Laravel Ecosystem Integration: Works seamlessly with Laravel’s validation system, migrations, and Form Requests, reducing friction in existing workflows.

Integration Feasibility

  • Low-Coupling: Installs as a dev dependency, ensuring it doesn’t bloat production environments. Artisan command-based workflow integrates naturally into Laravel’s CLI-driven development.
  • Schema-Aware: Dynamically inspects the database schema at runtime, making it self-documenting and adaptive to schema changes (e.g., migrations).
  • Form Request Generation: Automates the creation of StoreXRequest/UpdateXRequest classes, reducing repetitive boilerplate in API/controller layers.
  • Customization Points:
    • skip_columns config: Exclude columns (e.g., deleted_at, created_at) globally.
    • Manual overrides: Generated rules can be extended or modified post-generation.
    • Database-specific rules: Handles driver quirks (e.g., PostgreSQL’s jsonb, SQLite’s length limits).

Technical Risk

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.

Key Questions for Stakeholders

  1. Validation Strategy:

    • Should generated rules be enforced strictly (e.g., in APIs) or treated as suggestions for manual review?
    • Are there business-critical validations (e.g., custom regex, conditional rules) that cannot be auto-generated?
  2. Workflow Integration:

    • Should rule generation be automated in CI/CD (e.g., post-migration) or left as a developer task?
    • How should conflicts be handled when manually edited Form Requests exist?
  3. Database Diversity:

    • Does the project use multiple database drivers? If so, how should driver-specific quirks (e.g., SQLite limits) be addressed?
    • Are there unsupported column types (e.g., jsonb with nested validation) that require custom solutions?
  4. Maintenance:

    • Who will audit and maintain generated rules over time (e.g., as schema evolves)?
    • Should a custom validation layer (e.g., Laravel Policies) supplement auto-generated rules for complex logic?
  5. Testing:

    • How will validation tests (e.g., PHPUnit) account for auto-generated rules? Should they be regenerated before tests?
    • Are there performance-sensitive endpoints where validation overhead is a concern?

Integration Approach

Stack Fit

  • Laravel Core: Native support for Artisan commands, Form Requests, and validation, ensuring zero integration friction.
  • Database Layer: Works with Eloquent models, migrations, and raw schema inspection, making it ideal for database-centric applications.
  • API/Backend Services: Particularly valuable for CRUD-heavy APIs where validation boilerplate is repetitive.
  • Legacy Systems: Can retrofit validation to existing tables without rewriting business logic.

Migration Path

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.

Compatibility

  • Laravel Versions: Officially supports 11–13; test thoroughly on LTS versions (e.g., 10.x if needed).
  • Database Drivers: MySQL/PostgreSQL/SQLite are supported, but edge cases (e.g., float, jsonb) may require manual handling.
  • Third-Party Packages:
    • Conflicts: May clash with packages that modify validation (e.g., spatie/laravel-permission). Test with auth/role-based validation tools.
    • Synergy: Works well with Laravel Nova, Filament, or API platforms (e.g., Laravel Sanctum) for consistent validation.
  • Custom Columns: Unsupported types (e.g., array, custom enum) will skip generation; document these as known gaps.

Sequencing

  1. Pre-requisites:
    • Ensure database schema is stable (avoid during active migration phases).
    • Set up database backups in case of rule generation issues.
  2. Initial Setup:
    • Install package (composer require --dev).
    • Publish config (php artisan vendor:publish --tag="schema-rules-config").
    • Configure skip_columns (e.g., ['deleted_at', 'created_at', 'custom_skip']).
  3. Generation Workflow:
    • Batch Mode: Generate rules for all tables in a single command (e.g., php artisan schema:generate-rules --all if supported).
    • Selective Mode: Target specific tables (e.g., php artisan schema:generate-rules users --create-request).
  4. Validation:
    • Unit Tests: Regenerate rules and re-run validation tests.
    • Manual Review: Spot-check critical tables (e.g., users, payments).
  5. Deployment:
    • CI/CD Integration: Add a step to **
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle