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 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

Automatically generate Laravel validation rules based on your database table schema!

Frequently asked questions about Laravel Schema Rules
How do I generate Laravel validation rules from an existing database table?
Run `php artisan schema:generate-rules TableName` to auto-generate validation rules for an entire table. The package maps database columns to Laravel’s validation rules (e.g., `string`, `integer`, `required_if`) based on schema definitions. Rules are output to your terminal or saved to a file via config.
Can I generate Form Request classes directly from my database schema?
Yes, use `php artisan schema:generate-request TableName` to create a full Form Request class with validation rules derived from your table schema. The generated class includes methods like `rules()` and `authorize()`, ready for immediate use in your Laravel controllers.
Which Laravel versions and PHP versions does laracraft-tech/laravel-schema-rules support?
The package requires Laravel 9.x or 10.x and PHP 8.1+. It is built for modern Laravel applications and leverages features like Artisan commands and config publishing, which are fully supported in these versions. Check the [GitHub repository](https://github.com/laracraft-tech/laravel-schema-rules) for version-specific updates.
Does this package work with PostgreSQL’s jsonb or other advanced column types?
Yes, the package supports PostgreSQL’s jsonb columns and maps them to Laravel’s `json` validation rule. However, for complex nested validation (e.g., validating specific keys within jsonb), you’ll need to manually extend the generated rules. The package handles basic type conversion but relies on you for advanced logic.
How do I skip specific columns when generating validation rules?
Use the `--skip` flag to exclude columns, like `php artisan schema:generate-rules TableName --skip=column1,column2`. You can also configure globally skipped columns in the published config file under `schema-rules.php`, which is useful for columns like timestamps or foreign keys you handle separately.
Will this package interfere with my existing validation logic or Form Requests?
No, the package generates starter rules that you can override manually. It’s designed to reduce boilerplate while allowing full control. For example, if you generate a Form Request and later add custom rules (e.g., regex, conditional validation), those will persist even if you regenerate the rules.
How do I test validation rules generated by this package?
The package doesn’t include test cases, so you’ll need to manually test generated rules using Laravel’s built-in testing tools (e.g., `assertValid()` in PHPUnit or Pest). Focus on edge cases like max values for integers, precision for decimals, and nullable fields. Automate testing in your CI/CD pipeline to catch regressions when regenerating rules.
What happens if my database schema changes frequently? Will I need to regenerate rules often?
Yes, schema changes (e.g., adding/removing columns) require regenerating rules to stay in sync. Automate this in your CI/CD pipeline by triggering rule regeneration after migrations or schema changes. For example, add a GitHub Actions workflow to run `php artisan schema:generate-rules` whenever `migrate` completes.
Does this package support foreign key validation (e.g., ensuring referenced records exist)?
The package generates `exists:` rules for foreign keys to validate that referenced records exist in the related table. However, it doesn’t handle cascading validation (e.g., ensuring a parent record exists before creating a child). For complex relationships, manually extend the generated rules or use Laravel Policies for additional logic.
Are there alternatives if I need dynamic validation rules (e.g., role-based or conditional rules)?
If you need dynamic rules (e.g., validation based on user roles or runtime conditions), this package alone won’t suffice. Combine it with Laravel’s built-in features like `when()`, `sometimes()`, or custom validation traits. For role-based access, use Laravel Policies or Gates alongside the generated rules.
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.
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
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope