0
我正在嘗試在用戶表內的所需用戶的刪除按鈕中單擊時做出很好的確認屏幕。我的問題是我不能使用Bootstrap模式來刪除用戶,因爲如果模式沒有放在循環中,刪除最後一個用戶,但是如果在循環內部,它將會打印與找到的條目一樣多的模式。在刀片(Laravel)模板循環中添加確認模式(引導程序)
我的代碼如下(配售模式的循環,它應該是外面!)
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-9">
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Usuario</td>
<td>Nombre</td>
<td>Apellido</td>
<td>Email</td>
<td>Acceso</td>
</tr>
</thead>
<tbody>
@foreach($users as $key => $value)
<tr>
<td>{{ $value->username }}</td>
<td>{{ $value->first_name }}</td>
<td>{{ $value->last_name }}</td>
<td>{{ $value->email }}</td>
<td>{{ $value->role }}</td>
<td>
<a class="btn btn-small btn-success" href="{{ URL::to('usuarios/' . $value->id) }}">Mostrar</a>
<a class="btn btn-small btn-warning" href="{{ URL::to('usuarios/' . $value->id . '/edit') }}">Editar</a>
<a class="btn btn-small btn-danger" href="#" data-toggle="modal" data-target=".delete-user-modal">Borrar</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="col-md-3">
<a class="btn btn-small btn-info" href="#" data-toggle="modal" data-target=".create-user-modal">Crear usuario</a><br />
{{ HTML::ul($errors->all()) }}
</div>
</div>
</div>
</div>
<div class="modal fade delete-user-modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" >
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Eliminar usuario</h4>
</div>
<div class="modal-body">
<p>¿Estás seguro que deseas elminar el usuario <strong>{{ Auth::User()->username }}</strong>?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
{{ Form::open(array('url' => 'usuarios/' . $value->id, 'class' => 'pull-right')) }}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Borrar', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div>
</div>
</div>
</div>
public function destroy($id)
{
// buscar y eliminar usuario
$user = User::find($id);
$user->delete();
// redirigir a usuarios con mensaje mensaje
return Redirect::to('usuarios');
}