- How do I install laravel-schema-rules?
- Install it as a dev dependency with composer require laracraft-tech/laravel-schema-rules --dev. Optionally publish the config file using php artisan vendor:publish --tag="schema-rules-config" to customize skipped columns. No migrations or production service provider changes are required.
- Which Laravel versions does laravel-schema-rules support?
- The package is compatible with Laravel 8 through 13 according to its compatibility badge and evaluation notes. It relies on Laravel's schema builder and Artisan commands, so it fits convention-following Laravel apps. Check the Packagist badge for the exact latest supported range before adopting.
- How do I generate validation rules for a whole database table?
- Run php artisan schema:generate-rules table_name, replacing table_name with your actual table. The command inspects the live schema and prints a PHP array of basic rules you can copy into a Form Request or controller. You need a reachable database connection at generation time.
- How can I generate rules for only specific columns?
- The schema:generate-rules command supports limiting output to specific columns by naming them alongside the table. This is useful when only part of a table is user-editable. Review the README for the exact argument order for your package version.
- Can laravel-schema-rules create a Form Request class for me?
- Yes, the package can scaffold a Form Request class using the --create-request or -c flag. You can target a namespace such as Api\V1\StorePersonRequest with --file, so generated requests fit existing app/Http/Requests layouts. Treat the generated class as a starting point and add authorization and business rules manually.
- Which database drivers are supported for rule generation?
- The package supports MySQL, PostgreSQL, and SQLite, with driver-specific behavior for ranges and lengths. Because output depends on the driver and version used at generation time, generate rules against the same database engine as production where possible. SQLite locally and PostgreSQL in production can produce different min and max values.
- Why are decimal and float columns only getting required and numeric rules?
- Laravel Schema Rules maps float, decimal, and double columns to ['required', 'numeric'] without precision or scale bounds. The README states this limitation explicitly. For financial or measured values, add decimal, min, max, or between rules manually after generation.
- Does it generate unique, exists, or required_if validation rules?
- No, it derives rules from column definitions only, so it cannot infer uniqueness, cross-field invariants, conditional requirements, or authorization. Foreign keys become exists:table,id against the connection used during generation, which may need correction for cross-connection or schema-qualified references. Add uniqueness and required_if rules by hand before merging.
- Is laravel-schema-rules safe to use in production?
- It is designed as dev-only tooling installed with --dev and does not add runtime middleware, service providers, or container bindings. The generated rules are a floor, not a complete validation strategy, so production safety depends on human review for uniqueness, authorization, and business invariants. Avoid pasting production schema DDL into the hosted web equivalent if you handle regulated data.
- What happens when I use --force and overwrite generated Form Requests?
- The --force flag overwrites existing Form Requests silently, including any hand-tuned rules you added after generation. Since the tool's value comes from post-generation editing, use --force carefully and keep generated requests under version control. Decide whether you commit generated requests and own them or regenerate on demand, and review diffs before merging.