1
我在PHP中完全禁用,但是我的問題是,在對特定輸入有錯誤的驗證之後,如何在特定輸入中插入類?Laravel - 如果在驗證時出現錯誤,在特定輸入中插入類
例如,如果我在驗證中出現此錯誤:「電子郵件字段是必需的。」
如何在電子郵件輸入中插入特定的類?
登錄路線:
Route::group(['prefix' => 'admin'], function() {
Route::get('/', 'Admin\[email protected]');
Route::get('login', 'Admin\[email protected]');
Route::post('login', 'Admin\[email protected]');
Route::get('logout', 'Admin\[email protected]');
});
AdminController:
class AdminController extends AdminBaseController
{
public function index()
{
if(Auth::user()){
return view('admin/pages/admin/index');
}
return view('admin/pages/login/index');
}
}
AuthController:
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
private $redirectTo = '/admin';
public $loginPath = '/admin';
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
public function getLogin()
{
if(Auth::user()){
return redirect('/admin');
}
return view('admin/pages/login/index');
}
public function postLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6',
]);
}
}
我的刀片形式:
<form class="s-form" role="form" method="POST" action="/admin/login">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="s-form-item text">
<input type="text" name="email" value="{{ old('email') }}" placeholder="Email">
</div>
<div class="s-form-item text">
<input type="password" name="password" value="{{ old('password') }}" placeholder="Senha">
</div>
<div class="s-form-item">
@if ($errors->has())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br>
@endforeach
</div>
@endif
</div>
<div class="s-form-item s-btn-group s-btns-right">
<input class="s-btn" type="submit" value="Entrar">
</div>
</form>
明白了,並打印出錯? –
您是不是已經在密碼下面輸入錯誤了? –
是的,但它打印所有錯誤'$ errors-> all()',我想打印具體輸入下面的具體錯誤...明白了嗎? –