You have two actually different cases, validation and verification. If the verification error message uses modal, does the validation error message use it too?
NO (Short Answer)
if ($verify) {
return redirect()->route('shop.index');
}
return redirect()->route('shop.login', ['status' => 'error']);
@if(request()->input('status') == 'error')
<div class="modal fade" id="modal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Error</h5>
</div>
<div class="modal-body">
Login or password incorrect! Try again.
</div>
</div>
</div>
</div>
@endif
@if(request()->input('status') == 'error')
<script type="text/javascript">
$("#modal1").modal('show');
</script>
@endif
YES (Long Answer)
I don’t know what $this->validate
does, but I assume it’s the same thing as validate
method provided by the IlluminateHttpRequest
object.
If you look at the default LoginController
, you will find that the verification error message is the same as validation, using:
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
That means, you will have one action for both. But in your case, you separate them.
/******** VALIDATION ********/
// if validation fails, an exception will be thrown and
// the proper error response will automatically be sent back to the user.
$input = $req->validate($req, [
'email' => ['required', 'email'],
'password' => ['required'],
]);
/******** VERIFICATION ********/
$verify = Auth::attempt(['email' => $data['email'], 'password' => $data['password']]);
if ($verify) {
return redirect()->route('shop.index');
}
// return redirect()->route('shop.login', ['status' => 'error']);
// or
return redirect()->route('shop.login')
->with('status-verification', 'Login or password incorrect! Try again.');
@if($errors->any())
<div class="modal fade" id="modal-validation" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Error Validation</h5>
</div>
<div class="modal-body">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
</div>
</div>
</div>
@endif
@if(session('status-verification'))
<div class="modal fade" id="modal-verification" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Error</h5>
</div>
<div class="modal-body">
{{ session('status-verification') }}
</div>
</div>
</div>
</div>
@endif
<script type="text/javascript">
@if($errors->any())
$("#modal-validation").modal('show');
@endif
@if(session('status-verification'))
$("#modal-verification").modal('show');
@endif
</script>