{"id":21458766,"url":"https://github.com/robclancy/validation","last_synced_at":"2025-03-17T04:19:43.961Z","repository":{"id":7179544,"uuid":"8481645","full_name":"robclancy/validation","owner":"robclancy","description":"Validation","archived":false,"fork":false,"pushed_at":"2013-03-29T15:42:34.000Z","size":188,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T07:38:10.496Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/robclancy.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}},"created_at":"2013-02-28T15:16:30.000Z","updated_at":"2014-06-20T01:26:53.000Z","dependencies_parsed_at":"2022-08-20T01:20:20.718Z","dependency_job_id":null,"html_url":"https://github.com/robclancy/validation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fvalidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fvalidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fvalidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robclancy%2Fvalidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robclancy","download_url":"https://codeload.github.com/robclancy/validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243971180,"owners_count":20376784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-23T06:24:04.982Z","updated_at":"2025-03-17T04:19:43.936Z","avatar_url":"https://github.com/robclancy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"validation\n================\n\nThis isn't ready for use.\n\n\n\n\n\nThe following is a dump to explain things for feedback.\n\n\nFirst we have an alias, `Validatable` will alias `RobClancy\\Validation\\Illuminate`.\n\nTo use this for model validation you would do...\n\n```php\n// Note most of this would be in a base class\nclass Post extends Eloquent {\n\t\n\t// We import the validator methods\n\tuse Validatable;\n\t\n\t// Define the input and rules to validate, basic post validation\n\tpublic function defineInput()\n\t{\n\t\t$this-\u003einput('user_id')-\u003erequired()-\u003einteger();\n\t\t$this-\u003einput('post')-\u003erequired();\n\t}\n\t\n\t// Then we have our save method\n\tpublic function save()\n\t{\n\t\tif ( ! $this-\u003evalidate($this-\u003eattributes))\n\t\t{\n\t\t\treturn false;\n\t\t\t// User can now call $this-\u003egetErrors() for a list of errors\n\t\t}\n\t\t\n\t\t// Doing this means we can push Input::all() into the model and the validator will filter out what we need\n\t\t$this-\u003eattributes = $this-\u003egetValidatedInput();\n\t\t\n\t\treturn parent::save();\n\t}\n}\n```\n\nSo the above in a controller would be...\n```php\nclass PostController extends Controller {\n\n\t...\n\t\n\tpublic function postIndex()\n\t{\n\t\t$post = new Post(Input::all());\n\t\tif ( ! $post-\u003esave())\n\t\t{\n\t\t\treturn Redirect::back()-\u003ewithErrors($post-\u003egetErrors(), $post-\u003egetInput());\n\t\t}\n\t\t\n\t\treturn Redirect::to('success/page');\n\t}\n}```\n\nThen I had a use case for logging in, didn't want to validate input before sending to authentication on a model so can do this instead...\n```php\nclass LoginController extends Controller {\n\n\tuse Validatable;\n\n\t// getLogin method etc here\n\n\t// Define the input to validate against\n\tpublic function defineInput()\n\t{\n\t\t$this-\u003einput('email')-\u003erequired()-\u003eemail();\n\t\t$this-\u003einput('password')-\u003erequired();\n\t}\n\n\t// And once again use the new methods here\n\tpublic function postIndex()\n\t{\n\t\tif ( ! $this-\u003evalidate())\n\t\t{\n\t\t\treturn Redirect::back()-\u003ewithErrors($this-\u003egetErrors());\n\t\t}\n\t\t\n\t\t// run authentication\n\t}\n}\n```\n\nIn the controller example you can also skip the defineInput method and do this instead...\n```php\nclass LoginController extends Controller {\n\n\tuse Validatable;\n\t\n\t...\n\t\n\t\n\tpublic function postIndex()\n\t{\n\t\t$validate = $this-\u003evalidate(function($add)\n\t\t{\n\t\t\t$add-\u003einput('email')-\u003erequired()-\u003eemail();\n\t\t\t$add-\u003einput('password')-\u003erequired();\n\t\t});\n\t\n\t\tif ( ! $validate)\n\t\t{\n\t\t\treturn Redirect::back()-\u003ewithErrors($this-\u003egetErrors());\n\t\t}\n\t\t\n\t\t// authenticate\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobclancy%2Fvalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobclancy%2Fvalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobclancy%2Fvalidation/lists"}