我使用的是Bootstrap 3.7和Laravel 5.5。
我有一个表单,但它正在进入bootstrap崩溃。 而且,我使用的是Laravel Validator。
当出现错误时,如何显示表单(在打开页面时隐藏),因为验证程序页面已刷新。
所以我需要打开崩溃才能看到错误。这不太实际。
HTML:
@extends('layout.layout')
@section('content')
<div class="container">
<h1 class="page-header">
Administration
</h1>
<div class="row">
<div class="col-lg-12">
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
...
</div>
<div id="collapseOne" class="panel-collapse collapse">
...
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
...
</div>
<div id="collapseTwo" class="panel-collapse collapse">
...
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseAjoutEmploye">Ajout d'un employé</a>
</h4>
</div>
<div id="collapseAjoutEmploye" class="panel-collapse collapse">
<form class="form-horizontal" method="POST" action="{{ route('ajouterEmploye') }}">
{{ csrf_field()}}
<div class="form-group {{ $errors->has('email') ? 'has-error' : '' }}">
<label for="ajout-employe-email" class="col-md-4 control-label">Email </label>
<div class="col-md-6">
<input id="ajout-employe-email" type="text" class="form-control" name="email">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Enregistrer l'employé
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
PHP:
路线
Route::post('ajouterEmploye', 'AdministrationController@ajouterEmploye')->name('ajouterEmploye');
控制器:
public function ajouterEmploye(Request $request) {
$this->validate($request,[
'email' => 'required|email|exists:connexion'
] , [
'email.required' => 'Ce champ est requis',
'email.email' => 'Ce champ doit être un email',
'email.exists' => 'Cet email est inconnu'
]);
$user = User::getUserByEmail($request->email);
User::where('id_utilisateur', '=', $user->id_utilisateur)
->update(['id_statut' => 1]);
return redirect()->back()->with('message', "L'employé a bien été ajouté");
}
感谢您的帮助!