I'm getting this error.
Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException
I have a login view with a form, I validate the form with ajax, without a problem. When I try to return a view once I've successfuly logged in.
if ($validation->fails()){
return Response::json(array( 'success' => false, 'errors' => $validation->getMessageBag()->toArray() ));
}else if(Auth::attempt($loginData)){
$usuario=Usuario::find(Input::get('rut'));
return View::make('logged')->with(array('nombre' => $usuario->primer_nombre.' '.$usuario->apellido_paterno.' '.$usuario->apellido_materno,
'rut' => $usuario->id_usuario,
'tipo' => $usuario->id_tipo));
}else{ return Response::json(array( 'exists' => false, 'message' => 'El usuario no existe o la contraseña es inválida.' )); }
I guess the problem is in the last else statement,I get an 404 error.
This is the route:
Route::post('ingresar','LoginController@login');
The action on the form is ingresar
then I use the login method in LoginController
public function login(){
if(Request::ajax()){
//validamos el formulario.
$loginData = array(
'id_usuario' => Input::get('rut'),
'password' => Input::get('password')
);
$rules = array(
'rut' => 'required',
'password' => 'required',
);
$messages = array(
'required' => 'El campo :attribute es obligatorio.',
);
$validation = Validator::make(Input::all(), $rules, $messages);
if ($validation->fails()){
return Response::json(array(
'success' => false,
'errors' => $validation->getMessageBag()->toArray()
));
}else if(Auth::attempt($loginData)){
$usuario=Usuario::find(Input::get('rut'));
return View::make('logged')->with(array('nombre' => $usuario->primer_nombre.' '.$usuario->apellido_paterno.' '.$usuario->apellido_materno,
'rut' => $usuario->id_usuario,
'tipo' => $usuario->id_tipo));
}else{
return Response::json(array(
'exists' => false,
'message' => 'El usuario no existe o la contraseña es inválida.'
));
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.