laravel from delete最新的一条或只有一条数据时删不掉!

使用laravel 5.1自带的form表单进行删除,在删除的表单外面加了一个用来排序的表单,如果我有很多条数据,除了最上面的那条数据删除不掉(路由会跳到index()中),其他的都能删除,大致格式如下:
<!-- 排序 -->
{!! Form::model($goods,array('route' => 'admin.goods.sort','class'=>'form-horizontal','method'=>'put')) !!}

   <!-- 删除 -->
               {!! Form::open(['route' => ['admin.goods.destroy', $item->goods_id],'name'=>$item->goods_id, 'method'=>'delete']) !!}

                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        {{--<button type="submit" class="btn btn-danger">删除</button>--}}

                 {!! Form::submit('删除',array('class' => 'btn btn-danger')) !!}
                 {!!Form::close()   !!}
   <!-- 删除end -->

{!! Form::hidden('_method', 'PUT') !!}
{!! Form::close()  !!}
<!-- 排序end -->

完整代码:
<div class="box-body table-responsive no-padding">

            {!! Form::model($goods,array('route' => 'admin.goods.sort','class'=>'form-horizontal','method'=>'put')) !!}

                <table class="table table-hover">
                    <tr>
                        <th style="width: 50px">排序</th>
                        <th style="width: 100px">选择</th>
                        <th style="width: 50px">ID</th>
                        <th>名称</th>
                        <th style="width: 100px">分类</th>
                        <th style="width: 100px">编号</th>
                        <th style="width: 80px">价格</th>
                        <th style="width: 80px;display:none;">首页推荐</th>
                        <th style="width: 80px">位置推荐</th>
                        <th style="width: 80px">上下架</th>
                        <th style="width: 150px;">操作</th>

                    </tr>

                    @foreach ($goods as $item)
                    <tr>
                        <td>{!! Form::text('sort_order['.$item->goods_id.']',intval($item->sort_order),['style'=>'width:40px; text-align:center']) !!}</td>
                        <td>{!! Form::checkbox('selGoods', $item->goods_id, false,['id'=>$item->goods_id,'style'=>'width:40px; text-align:center']) !!}</td>
                        <td>{{$item->goods_id}}</td>
                        <td>{{$item->goods_name}}</td>
                        <td>{{$item->cat_name}}</td>
                        <td>{{$item->goods_sn}}</td>
                        <td>{{$item->market_price}}</td>
                        <td style="display:none;">
                                @if($item->is_home_recommend==1)
                                <i class="is_home_recommend glyphicon glyphicon-check" style=" cursor: pointer;color: green;" goods_id="{{$item->goods_id}}" name='is_home_recommend'></i>
                                @elseif($item->is_home_recommend==0)
                                <i class="is_home_recommend glyphicon glyphicon-unchecked" style=" cursor: pointer;color: red;" goods_id="{{$item->goods_id}}" name='is_home_recommend'></i>
                                @endif
                        </td>
                        <td>
                                @if($item->is_cat_recommend==1)
                                <i class="is_cat_recommend glyphicon glyphicon-check" style=" cursor: pointer;color: green;" goods_id="{{$item->goods_id}}" name='is_cat_recommend'></i>
                                @elseif($item->is_cat_recommend==0)
                                <i class="is_cat_recommend glyphicon glyphicon-unchecked" style=" cursor: pointer;color: red;" goods_id="{{$item->goods_id}}" name='is_cat_recommend'></i>
                                @endif
                        </td>
                        <td>
                                @if($item->is_on_sale==1)
                                <i class="toggle_sale glyphicon glyphicon-check" style=" cursor: pointer;color: green;" goods_id="{{$item->goods_id}}"></i>
                                @elseif($item->is_on_sale==2)
                                <i class="toggle_sale glyphicon glyphicon-unchecked red" style=" cursor: pointer;color: red;"  goods_id="{{$item->goods_id}}"></i>
                                @endif
                        </td>
                        <td>
                            <a href="{{Route('admin.goods.edit',$item->goods_id)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                            <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$item->goods_id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>

                            <div id="modal{{$item->goods_id}}" class="modal fade">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                            <h4 class="modal-title">删除警告:</h4>
                                        </div>
                                        <div class="modal-body">
                                            <p>确认要删除[{{$item->goods_name}}]吗?</p>
                                        </div>
                                        <div class="modal-footer">


                                            {!! Form::open(['route' => ['admin.goods.destroy', $item->goods_id],'name'=>$item->goods_id, 'method'=>'delete']) !!}

                                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                            {{--<button type="submit" class="btn btn-danger">删除</button>--}}
                                            {!! Form::submit('删除',array('class' => 'btn btn-danger')) !!}

                                            {!!Form::close()   !!}
                                        </div>
                                    </div><!-- /.modal-content -->
                                </div><!-- /.modal-dialog -->
                            </div><!-- /.modal -->

                        </td>
                    </tr>
                    @endforeach

                </table>
                {!! Form::hidden('_method', 'PUT') !!}


                {!! Form::close()  !!}
            </div>
            <!-- /.box-body -->
01.gif
已邀请:

xiaoluyouyue

赞同来自:

源代码贴出来

要回复问题请先登录注册