Làm cách nào để tùy chỉnh thông báo lỗi (chẳng hạn như "These credentials do not match our records."
) được hiển thị khi đăng nhập/đăng ký không thành công mà không cần phải chạm vào tệp nền tảng? Tôi đang tìm kiếm một giải pháp và hy vọng là một tao nhã, ít nhất là không chạm AuthenticatesAndRegistersUsers
cũng không ThrottlesLogins
:)Laravel 5.2 - Auth: hiển thị thông báo lỗi tùy chỉnh
Tôi đang sử dụng AuthController
và các hình thức cung cấp bởi Laravel sau khi thực hiện:
php thợ thủ công thực hiện: auth
Bộ điều khiển:
(nó chỉ có một constructor và hai phương pháp, phần còn lại rơi vào các sáng lập nạt, răn các phương pháp này :)
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
Mẫu:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-sign-in"></i>Login
</button>
<a class="btn btn-link" href="{{ url('/password/reset') }}">Forgot Your Password?</a>
</div>
</div>
Cảm ơn bạn!
Cảm ơn câu trả lời @lagbox! Làm thế nào về tất cả các thông báo lỗi khác, "Trường tên là bắt buộc." hoặc "Xác nhận mật khẩu không khớp." trên mẫu đăng ký người dùng? –
đó là các thông báo xác thực, bạn có thể điều chỉnh authcontroller để truyền mảng thông điệp của riêng bạn vào cuộc gọi xác thực hoặc cập nhật các thư đó trên toàn cầu trong tệp lang mà chúng kéo từ đó. – lagbox
Được chấp nhận và upvoted, cảm ơn bạn tốt sir! –