{"id":19379638,"url":"https://github.com/larapack/command-validation","last_synced_at":"2025-04-23T19:32:55.453Z","repository":{"id":57011718,"uuid":"46981713","full_name":"larapack/command-validation","owner":"larapack","description":"Enable a method for Artisan Commands to validate the output of methods like `ask`.","archived":false,"fork":false,"pushed_at":"2017-02-10T10:09:58.000Z","size":23,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T19:22:31.857Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/larapack.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-27T13:29:21.000Z","updated_at":"2019-11-29T15:30:34.000Z","dependencies_parsed_at":"2022-08-21T15:10:25.481Z","dependency_job_id":null,"html_url":"https://github.com/larapack/command-validation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larapack%2Fcommand-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larapack%2Fcommand-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larapack%2Fcommand-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/larapack%2Fcommand-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/larapack","download_url":"https://codeload.github.com/larapack/command-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249598223,"owners_count":21297464,"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-10T09:10:48.275Z","updated_at":"2025-04-23T19:32:55.165Z","avatar_url":"https://github.com/larapack.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Command Validation\nEnable a method for Artisan Commands to validate the output of methods like `ask`.\n\n## Installing\n\nInstall using composer `composer require \"larapack/command-validation 1.*\"`.\n\n## Usage\n\nFirst add the trait `Validateable` to your Artisan Command.\n```\n\u003c?php\n\nnamespace App\\Console\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Larapack\\CommandValidation\\Validateable;\n\nclass ExampleCommand extends Command\n{\n  use Validateable;\n  \n  // ...\n}\n```\n\nThen use the `validate`-method:\n```\n  public function fire()\n  {\n    // We want to get the age from the user, but we would like to validate it.\n    // So we use the validate method.\n    $age = $this-\u003evalidate(function() {\n      // Here we ask the question we want and return the output\n      // Any method returning a value from the command line input can be used here.\n      return $this-\u003eask('What is your age?', null);\n    }, function($value) {\n      // Here we validate the value\n      // If the value is NOT valid, we should return a error message.\n      // If the value is valid, we don't need to return anything.\n      // NOTE: Returning true will also be valid.\n      if (!is_numeric($value)) return \"Age [{$value}] is not numeric.\";\n    });\n    \n    // Once we are here you will have the validage age\n    $this-\u003einfo(\"So you are {$age} years old.\");\n  }\n```\n\nIt will look like this:\n\n![Command Line Example](https://raw.githubusercontent.com/larapack/command-validation/master/resources/command-line-example.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarapack%2Fcommand-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flarapack%2Fcommand-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flarapack%2Fcommand-validation/lists"}