Ad
Laravel - Getting The Validation Error
in Laravel, is there any way to know which rule was invalid. For example:
'email': 'email|max:20'
And let's assume that I want to know is the email max rule failed
Ad
Answer
If you want to get error message considering specific field, then mention the name of the Validation object key
on messages
array. Ref
If validation has failed, you may retrieve the error messages from the validator.
if ($validator->fails())
{
$messages = $validator->messages();
}
echo $messages;
You may also access an array of the failed validation rules, without messages. To do so, use the failed method:
$failed = $validator->failed();
Retrieving All Error Messages For A Field
foreach ($messages->get('email') as $message)
{
//
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad