这是我的要求:
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|email',
'password' => 'required|min:6',
];
}
}
现在我想在我的登录帖子方法中使用它:
public function loginUser(LoginRequest $request) {
if(empty(AuthManager::getAuthErrors())) {
if(!Auth::attempt($request->only(['email', 'password'], $request->has('remember')))) {
return view('auth.auth', ['status' => '505', 'mode' => 'login']);
}
return redirect('/dashboard')->with('success', 'logged_in');
}
return view('auth.auth', ['status' => '505', 'mode' => 'login', 'errors' => AuthManager::getAuthErrors()]);
}
最后,我在auth.auth刀片中使用如下:
@foreach($errors as $error)
<div class="error">
<p>{{ trans('auth.errors.'.$error) }}</p>
</div>
@endforeach
所有内容都被正确翻译,除非我自己的AuthManager响应被触发,否则我从未得到任何响应,就像AuthManager检查用户是否已经登录一样。
答案 0 :(得分:0)
试试这个..如果您的验证失败并且在显示错误消息时遇到问题。
@foreach($errors->all() as $error)
<div class="error">
<p>{{ trans('auth.errors.'.$error) }}</p>
</div>
@endforeach