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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners