{"id":15188531,"url":"https://github.com/sandeep-daffodilsw/laravel-model-validator","last_synced_at":"2026-02-14T21:32:54.096Z","repository":{"id":249813675,"uuid":"832665014","full_name":"sandeep-daffodilsw/laravel-model-validator","owner":"sandeep-daffodilsw","description":"Easily define and manage validation rules directly within your Eloquent models, streamlining your code by avoiding clutter in controllers and eliminating the need for separate form request classes.","archived":false,"fork":false,"pushed_at":"2024-07-24T09:15:30.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-11T09:04:11.826Z","etag":null,"topics":["database","eloquent","eloquent-models","laravel","laravel-framework","laravel-model-validator","model","model-validation","php","sandaffo","sandaffo-laravel-model-validator","sandeep-daffodil","sandeep-daffodilsw","validation"],"latest_commit_sha":null,"homepage":"https://github.com/sandeep-daffodilsw/laravel-model-validator","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandeep-daffodilsw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-23T13:29:03.000Z","updated_at":"2024-07-24T09:49:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed86fa1b-1195-4bc8-b06f-f3f37eca67bc","html_url":"https://github.com/sandeep-daffodilsw/laravel-model-validator","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"f62cb58fb131007f8bae0cef219900e3f22cab72"},"previous_names":["sandeep-daffodilsw/laravel-model-validator"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/sandeep-daffodilsw/laravel-model-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeep-daffodilsw%2Flaravel-model-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeep-daffodilsw%2Flaravel-model-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeep-daffodilsw%2Flaravel-model-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeep-daffodilsw%2Flaravel-model-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandeep-daffodilsw","download_url":"https://codeload.github.com/sandeep-daffodilsw/laravel-model-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandeep-daffodilsw%2Flaravel-model-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29456259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T21:29:27.764Z","status":"ssl_error","status_checked_at":"2026-02-14T21:28:11.111Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","eloquent","eloquent-models","laravel","laravel-framework","laravel-model-validator","model","model-validation","php","sandaffo","sandaffo-laravel-model-validator","sandeep-daffodil","sandeep-daffodilsw","validation"],"created_at":"2024-09-27T19:21:50.769Z","updated_at":"2026-02-14T21:32:54.064Z","avatar_url":"https://github.com/sandeep-daffodilsw.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Laravel Model Validator\n\nA Laravel package to add validation rules and messages at the model level.\n\nAfter install this package, you don't need to write the validation rules inside controller or form request, you can add them inside model and directly use methods to validate.\n\nAdding validation rules inside model itself makes model readable for developers.\n\n## Installation\n\nInstall the package via composer:\n\n```bash\ncomposer require sandaffo/laravel-model-validator\n```\n\n## Usage\n\n### Adding Validation to a Model\n\nTo add validation to a model, define the `rules` and `messages` properties in your model:\n\n```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    // define rules array\n    public static $rules = [\n        'title' =\u003e 'required|string|max:255',\n        'slug' =\u003e 'required|string|max:255|unique:posts',\n        'description' =\u003e 'required|string|min:8',\n    ];\n\n    // messages are optional, only provide when want customize message\n    public static $messages = [\n        'title.required' =\u003e 'The title field is required.',\n        'slug.required' =\u003e 'The slug field is required.',\n        'description.required' =\u003e 'The description field is required.',\n    ];\n}\n```\n\n### Example\n\nBelow is an example demonstrating the usage of the package:\n\n```php\n$p = new Post();\n$p-\u003etitle = \"Test Post One\";\n$p-\u003eslug = \"test-post-one\";\n$p-\u003edescription = \"Test post one description\";\n\nif ($p-\u003eisValid()) { // $p-\u003eisValid() returns true or false\n    echo \"Post is valid\";\n    $p-\u003esave();\n} else {\n    echo \"Post is not valid\";\n    print_r($p-\u003eerrors());\n}\n```\n\n### Tinker Example\n\n```bash\n$ php artisan tinker\n```\n\n```php\n$p = new Post();\n$p-\u003etitle = \"Test Post One\";\n$p-\u003eslug = \"test-post-one\";\n$p-\u003edescription = \"Test post one description\";\n\n$p-\u003eisValid(); // true or false\n$p-\u003eerrors(); // []\n\n$p-\u003eerrorMessages(); // [] single dimensional array of all error messages\n\n$p-\u003egetRules(); // to get the defined rules if you need somewhere\n// [\n//     \"title\" =\u003e \"required|string|max:255\",\n//     \"slug\" =\u003e \"required|string|max:255|unique:posts\",\n//     \"description\" =\u003e \"required|string|min:8\",\n// ]\n\n$p-\u003egetMessages(); // [] of defined custom error messages\n\n$p-\u003egetValidator(); // return Validator object if you need\n// Illuminate\\Validation\\Validator { ... }\n\n$p-\u003egetValidator()-\u003eerrors();\n// Illuminate\\Support\\MessageBag { ... }\n\n$p-\u003esave(); // true\n\n$p;\n// App\\Models\\Post {\n//     title: \"Test Post One\",\n//     slug: \"test-post-one\",\n//     description: \"Test post one description\",\n//     updated_at: \"2024-07-24 08:45:45\",\n//     created_at: \"2024-07-24 08:45:45\",\n//     id: 1,\n// }\n```\n\n## Methods\n\n- `isValid()`: Checks if the model is valid according to the defined rules.\n- `errors()`: Returns an array of validation errors.\n- `errorMessages()`: Returns an array of error messages.\n- `getRules()`: Returns the validation rules.\n- `getMessages()`: Returns the validation messages.\n- `getValidator()`: Returns the validator instance.\n\n## License\n\nThis package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandeep-daffodilsw%2Flaravel-model-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandeep-daffodilsw%2Flaravel-model-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandeep-daffodilsw%2Flaravel-model-validator/lists"}