php @error指令未在laravel视图中显示错误

vdzxcuhz  于 2023-10-15  发布在  PHP
关注(0)|答案(3)|浏览(102)

我正在开发自定义Laravel登录实现。我已经从控制器返回了如下错误:

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

下面是我的视图实现来提取这个错误:

<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>

我只想用这种方式。而不是其他方法来显示错误,因为代码最小化。使用Laravel 7.0+

qnakjoqk

qnakjoqk1#

试试这个:

<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>
qf9go6mv

qf9go6mv2#

请再试一次:

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

cyej8jka3#

我也遇到了同样的问题,因为我的朋友。我从config/app.php中删除了Adgbar的服务提供程序。然后@error又开始正常工作了

相关问题