0
I would like if this error when logging in to return a message to the user
In my view login.blade.php is like this
div class="login-form">
<form action="{{ route('logar') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
{{--<h2 class="text-center">Log in</h2>--}}
<div class="text-center">
<img src="{{ URL('img/logo_poraque.png') }}" class="img-rounded" alt="Cinque Terre" width="150">
</div>
<br />
@if ($errors->has('msg'))
<div style="text-align: center">
<span class="help-block has-error" >
<strong>{{ $errors->first('msg') }}</strong>
</span>
</div>
@endif
<div class="form-group has-feedback {{ $errors->has('login') ? ' has-error' : '' }}">
<input type="text" class="form-control" placeholder="Username" required="required" name="login" value="{{ old('login') }}">
@if ($errors->has('login'))
<span class="help-block">
<strong>{{ $errors->first('login') }}</strong>
</span>
@endif
</div>
<div class="form-group has-feedback {{ $errors->has('senha') ? ' has-error' : '' }}">
<input type="password" class="form-control" placeholder="Password" required="required" name="senha">
@if ($errors->has('senha'))
<span class="help-block">
<strong>{{ $errors->first('senha') }}</strong>
</span>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Log in</button>
</div>
<!-- <div class="clearfix">
<label class="pull-left checkbox-inline"><input type="checkbox"> Remember me</label>
<a href="#" class="pull-right">Forgot Password?</a>
</div>
-->
</form>
On my route web php. is like this:
Route::post( '/logar', [ 'as' => 'logar', 'uses' => 'UsuarioController@logar' ] );
In my Usuariocontroller.php is like this:
public function logar(Request $request){
$login = $request->input( 'login' );
$senha = $request->input( 'senha' );
$usuario = Usuario::where( [
['usua_login', $login]
])->first();
$user = Usuario::where( [
['usua_login', $login],
['usua_senha', sha1( $senha )]
])->first();
if( $user !== null ){
Session::put([
'login' => $login,
'id' => $user->usua_id
]);
return redirect()->route('telaPrincipal');
}else{
$msg = array(
"msg" => "Login ou senha não são válidos"
);
return redirect()->back()->withErrors( $msg )->withInput();
}
}
But when I error the password, it returns to the login and no message
What can it be?
If I give the print_r( )
in the controller it shows where it drops but does not return with the message in the view.
I think it may be in the Blade in the form that sends the errors tries to validate with @if($errors->any())
– Panda
Just remember that the site snippet DOES NOT work when the code is not only HTML/CSS/JS, so there is no reason to use it in other situations. Use, for these cases, the code snippet tool,
{}
.– Woss
@Panda even so , came back nothing.
– adventistaam
@Andersoncarloswoss I’m actually using in Blade.php which is like this:
{{ }}
– adventistaam
Maybe that’s not the kind of answer you’d like, but have you tried using auth ? Goes to the root of the project and creates with Artisan, "php Artisan make:auth" it will create the complete basic system of authentication already with the errors handled; then you edit the views it creates in Resources/views/auth and ready to go.
– Isaac Angelo
To write a code instead of a string {!! !!};
– Isaac Angelo
This code worked before. I don’t understand why it stopped. If at least this error
– adventistaam
I prefer to create my own authentication
– adventistaam