Source: ryangjchandler.co.uk

Validating Laravel Console Input

Category: Laravel

When distributing console commands in a package or within an application, making sure data is in the correct format can be important. Run the following command in your terminal: This will create a new file in app/Console/Commands called MakeUserCommand.php with all of the normal command boilerplate.

If you wanted to validate this input, all you need to do is pass the data through to a new Validator and handle any errors.

If you went ahead and did this for the email too, you can be confident that the data being provided is valid.

If the validation fails and errors are shown to the user, instead of returning and exiting the process, we can instead return $this->askWithValidation so that the user is asked the same question again.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners