我在表单上有一个boostrap模式。当我保存数据并通过成功验证时。
我让我重定向了一个视图索引,但是我得到了状态代码302,而不是重定向我
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');
我的重定向转到控制器的路径
return Redirect::to('showuser')->with('status','ok_create');
路由
//Rutas del sistema
Route::Controller('users','UsersController');
Route::get('showuser','UsersController@getIndex');
方法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');
}
}
如果状态为ok_create,请在我的视图中显示用户已创建并关闭窗口模式。
@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>
但不行,这是问题吗?
我想显示用户列表和关闭模式,我得到了回复但是没有用
当我按下表单的事件保存时。我有关闭窗口模式并显示用户列表