How to Display Validation Errors Next to Each Related Input Field in Laravel 5?
You can use something like this :
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
<label for="name" class="col-sm-3 control-label">Name: </label>
<div class="col-sm-6">
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
Laravel Introduced The @error Directive in version 6 and 7
<input id="title" type="text" name="title" class="@error('title') is-invalid @enderror">
@error('title')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
documentation
@Zorx has given a right solution. But what if there are multiple errors and you want to display all of them at once.
According to the documentation you could use:
Retrieving All Error Messages For A Field
foreach ($errors->get('email') as $message) {
//
}
If you are validating an array form field, you may retrieve all of the messages for each of the array elements using the * character:
foreach ($errors->get('attachments.*') as $message) {
//
}
Retrieving All Error Messages For All Fields
foreach ($errors->all() as $message) {
//
}