【发布时间】:2015-07-27 09:13:34
【问题描述】:
我有一个 subscribers 表:
当我点击 delete 时,btn 会带来一个确认模式:
我已经很接近了,但是当我点击删除时,即使我没有按最后一个 delete btn,它也会继续删除列表中的最后一个。
我知道我必须在某个地方使用这个{!! Form::hidden('$id', $subscribe->id)!!},我只是不知道应该把它放在哪里。
表格
<?php $x = 0; ?>
<div class="container">
<div class="row">
<a href="subscribe/create" class="btn btn-sm btn-success "> <span class="fa fa-plus"></span> Create </a><br><br>
<table class="table">
{{--Table Header--}}
<thead class="thin-border-bottom">
<th width="50" >#</th>
<th width="200" >Email</th>
<th width="100" >Subscribe On </th>
<th width="100" >Delete </th>
</thead>
{{--Table Body--}}
<tbody>
<tr>
@foreach( $subscribes as $subscribe)
<?php $x = $x+1; ?>
<td>{{ $x }}</td>
<td>{{ $subscribe->email or '' }}</td>
<td>{{ $subscribe->created_at or '' }}</td>
<td><a data-toggle="modal" data-target="#delete_subscriber" type="button" class="btn btn-danger btn-xs">Delete</a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
模态
<div class="modal fade" id="delete_subscriber" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class=" col-lg-5"> </div>
<div class=" center col-lg-2">
{!! Form::model($subscribe, array( 'route' => array('subscribe.destroy', $subscribe->id),'method' => 'DELETE')) !!}
<hr style="height:300pt; visibility:hidden;" />
{!! Form::submit ('Delete This Subscriber', array('class'=> 'btn btn-danger btn-lg btn-block', 'data-rel'=>"tooltip" , 'title'=>"Are you sure ?", 'data-placement'=>"top"))!!}<br><br>
<button data-rel="tooltip" title="Go Back" data-placement="bottom" type="button" class="btn btn-primary btn-lg btn-block" class="close" data-dismiss="modal" > Cancel </button> <br>
{!! Form::hidden('$id', $subscribe->id)!!}
{!! Form::close()!!}
</div>
</div>
谁能告诉我,我怎样才能删除正确的?
如何阻止我的应用程序删除列表中的最后一个对象?
控制器
public function destroy($id){
$subscribe = Subscribe::find($id);
$subscribe->delete();
return Redirect::to('subscribe')
->with('success','The web directory was deleted succesfully!');
}
【问题讨论】:
-
我们可以看看你的控制器吗?
-
如果你卡住了,请回复我的代码 100% 工作
-
@Adnan :您的答案不适用于 Modal 这正是我想要做的。
标签: php laravel laravel-4 laravel-5