php - @error directive is not displaying errors in laravel view

I'm working on custom Laravel login implementation. I have returned the error from controller as follows:

$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
  // Authentication passed...
  return redirect()->intended('surveys');
}else {
  return redirect()->back()->withErrors(['email', 'The Message']);
}

Here is my view implementation to extract this error:

<div class="col-md-6">
   <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
@error('email')
  <span class="invalid-feedback" role="alert">
      <strong>{{ $message }}</strong>
  </span>
@enderror
</div>

I want to use only this way. Not the other method to display error because of code minimization. I'm using Laravel 7.0+

Answer

Solution:

Try this :

<div class="col-md-6">
     <input id="email" type="email" class="form-control @if($errors->has('email'))  is-invalid @endif " name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
  @if($errors->has('email'))
      <div class="error"></div>
      <span class="invalid-feedback" role="alert">
           <strong>{{ $errors->first('email') }}</strong>
       </span>
  @endif
</div>

Answer

Solution:

Please try it again:

$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
  // Authentication passed...
  return redirect()->intended('surveys');
}else {
  return redirect()->back()->withErrors(['email' => 'The Message']);
}

Source