@error指令不在laravel视图中显示错误 [英] @error directive is not displaying errors in laravel view

查看:54
本文介绍了@error指令不在laravel视图中显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究自定义的Laravel登录实现.我从控制器返回了以下错误:

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>

我只想用这种方式.由于代码最小化,因此不是显示错误的另一种方法.我正在使用Laravel 7.0 +

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

推荐答案

请重试:

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

这篇关于@error指令不在laravel视图中显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆