I have one boostrap modal on a form. When I save the data and pass the success validation.
It has me redirect a the view index, but I get the status code 302, and not redirect me well
public function postCreate()
{
//validamos reglas inputs
$rules = array(
'inputuser' => 'required|max:10',
'inputpassword' => 'required|min:8',
'inputpassword1' => 'required|min:8',
'inputemail' => 'required|email|unique:users,email'
);
$validation = Validator::make(Input::all(), $rules);
//Si no pasa la validacion
if($validation->fails())
{
//Obtenemos los mensajes de error de la validation
$messages = $validation->messages();
//Redireccionamos a nuestro formulario de atras con los errores de la validación
if(Request::ajax())
{
return Response::json(array('errors' => $messages));
}
else
{
return Redirect::back()->withInput()->withErrors($validation);
}
}
//Si todo ha ido bien guardamos
$password = Input::get('inputpassword');
$user = new User;
$user->username = Input::get('inputuser');
$user->password = Hash::make($password);
$user->email = Input::get('inputemail');
$user->admin = (Input::get('es_admin') == '1') ? 1 : 0;
//guardamos
$user->save();
//redirigimos a usuarios
return Redirect::to('showuser')->with('status','ok_create');
my redirect goes to the route of the controller
return Redirect::to('showuser')->with('status','ok_create');
routes
//Rutas del sistema
Route::Controller('users','UsersController');
Route::get('showuser','UsersController@getIndex');
the method getIndex
class UsersController extends BaseController
{
public function __construct() {
$this->beforeFilter('auth'); //bloqueo de acceso
}
public function getIndex()
{
$my_id = Auth::user()->id;
$is_admin = Auth::user()->admin;
//control permissions only access administrator
if($is_admin==1)
{
$users = User::where('admin', '<>', '1')->where('id', '<>', $my_id)->get();
return View::make('admin/users.index')->with('users',$users);
}
else
{
return View::make('errors.access_denied');
}
}
if status ok_create, show me in my view the user has created and close window modal.
@if(!empty($status) && $status == 'ok_create')
<script>
$('#box-modal').on('shown', function () {
alert('hola');
$(this).modal('hide');
</script>
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert">×</a>
<i class="fa fa-check-square-o"></i> El usuario {{ $user->username }} fue creado con exito
</div>
@endif
<form role='form' class='form-horizontal' method='post'>
@if(Auth::check() && Auth::user()->admin)
<a id="link-modal" class='btn btn-primary pull-right' data-toggle='modal' data-target="#box-modal"><i class='fa fa-plus'></i> Alta usuario</a>
@endif
<h2>Listado de usuarios</h2>
@if($users && !$users->isEmpty())
<table class='table table-striped'>
<thead>
<tr>
<th>Seleccionar</th>
<th>#</th>
<th>Nombre de usuario</th>
<th>Email</th>
<th>Administrador</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td class='text-center'><input type='checkbox' name='rusuario[]' value='{{ $user->id }}' id='{{ $user->id }}' /></td>
<td class='text-center'>{{ $user->id }}</td>
<td class='text-center'>{{ $user->username }} </td>
<td class='text-center'>{{ $user->email }} </td>
<td class='text-center'>@if ($user->admin == 1) SI @else NO @endif</td>
@if(Auth::check() && Auth::user()->admin)
<td><a href="#" class="btn btn-primary" role="button"><i class="fa fa-pencil fa-fw"></i>Modificar</a></td>
@endif
</tr>
@endforeach
</tbody>
but don´t work, which is the problem?
I want to show the user´s list and close modal, I get the response but dont work
When I press the event save of my form. I have close window modal and show user list