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

Laravel Validable Laravel Package

padosoft/laravel-validable

A Laravel package that adds model-level validation via a Validable trait. Define rules and messages directly on Eloquent models and validate automatically before save or update, keeping persistence logic cleaner and data safer.

View on GitHub
Deep Wiki
Context7

padosoft/laravel-validable brings self-validating behavior to Eloquent models via a lightweight Validable trait. Define validation rules directly on your model and let the package validate attributes automatically during save/update operations, keeping controllers and form requests lean.

  • Model-level rules: declare $rules, custom messages, and attribute names alongside your model.
  • Automatic validation: runs Laravel’s validator on save/update and blocks invalid data.
  • Native exceptions: throws Laravel’s ValidationException for familiar error handling.
  • Custom messages: tailor validation feedback per model without duplicating logic.
  • Minimal setup: integrate with a trait—no schema changes required.
Frequently asked questions about Laravel Validable
How do I install padosoft/laravel-validable?
Install the package with Composer by running composer require padosoft/laravel-validable in your Laravel project. Then add the Validable trait to the Eloquent model you want to validate. If your Laravel version does not use package auto-discovery, check the package README for any service provider registration steps.
Which Laravel versions are supported by laravel-validable?
The package is a Laravel trait for Eloquent models, so support depends on the version constraints declared in its composer.json. Check the repository's composer.json or Packagist page before installing in a specific Laravel application. That is the most reliable way to confirm compatibility with your Laravel and PHP versions.
How do I define validation rules on a Laravel model with the Validable trait?
Add the Validable trait to your Eloquent model and define the rules directly on the model, typically in a rules property or method as described in the package README. The trait then uses those rules when the model is saved. This keeps validation close to the data it protects instead of scattering it across controllers.
Does laravel-validable validate automatically on save and update?
Yes. The Validable trait is designed to auto-validate an Eloquent model on save, which covers both creating and updating records through Eloquent. When the model is saved, the defined rules are applied before the write proceeds. If validation fails, the save is stopped according to the package's validation behavior.
How do I customize validation messages for a Validable model?
Define your custom messages on the model alongside the validation rules, as shown in the package documentation. The trait uses those model-level messages when validation runs on save. This lets you keep field-specific wording close to the model instead of duplicating messages in controllers.
What happens when validation fails on an Eloquent model using Validable?
When the model's data does not pass the rules, the trait prevents the save and reports the validation failure. In a typical Laravel setup this surfaces as a validation exception that your application can handle. You should catch or convert that exception in your controller or request layer if you need a custom JSON or redirect response.
Can I use Validable together with Laravel FormRequest validation?
Yes, the two approaches can complement each other. FormRequest validation is useful for request-specific input checks, while the Validable trait enforces model-level rules whenever the model is saved. Using both gives you request validation and a data integrity safeguard close to the Eloquent model.
Does laravel-validable support custom validation rules and Rule objects?
The trait relies on Laravel's validation system for the rules defined on the model, so standard Laravel rule strings and custom rule classes can generally be used. Confirm the exact supported syntax in the package README or source code. If you rely on advanced rule objects, test them in your application before rolling out widely.
How do I test a Laravel model that uses the Validable trait?
Write feature or unit tests that create and save the model with both valid and invalid attribute sets. For invalid data, assert that the expected validation exception is thrown and that the record is not persisted. For valid data, assert that the model saves successfully and the attributes are stored as expected.
Is padosoft/laravel-validable actively maintained, and what are alternatives?
Check the GitHub repository for recent commits, releases, and open issues to judge current maintenance. Alternatives include Laravel FormRequest validation, manual Validator calls, or model event listeners that validate before saving. The Validable trait is a good fit when you want rules and messages defined directly on the Eloquent model.
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.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections