Php 如何定义链接到Laravel 4中destroy()函数的路由?

Php 如何定义链接到Laravel 4中destroy()函数的路由?,php,laravel,laravel-4,routes,url-routing,Php,Laravel,Laravel 4,Routes,Url Routing,我在路由中定义了如下资源: Route::resource('shops', 'shopsController'); Route::get('shops/{id}/destroy', 'shopsController@destroy'); 我需要创建一个链接来删除一个项目 <a class="btn btn-xs btn-danger" href="{{ URL::to('shops/'. $row->id . '/destroy') }}" > </a>

我在路由中定义了如下资源:

    Route::resource('shops', 'shopsController');
Route::get('shops/{id}/destroy', 'shopsController@destroy');
我需要创建一个链接来删除一个项目

<a class="btn btn-xs btn-danger" href="{{ URL::to('shops/'. $row->id . '/destroy') }}" > </a>
那么,我如何强制URL通过默认路径,通过其资源,获得销毁功能

我试过了

href="{{ route('shops.destroy', $row->id ) }}" data-method="delete" 
但是我将我重定向到show()

试试这个

 <a class="btn btn-xs btn-danger" href="{{ route('shops.destroy',array($row->id)) }}" data-method="delete" rel="nofollow" data-confirm="Are you sure you want to delete this?">Delete this entry</a>

试试这个

 <a class="btn btn-xs btn-danger" href="{{ route('shops.destroy',array($row->id)) }}" data-method="delete" rel="nofollow" data-confirm="Are you sure you want to delete this?">Delete this entry</a>


您不能通过锚定标记href attr删除用户,您需要使用表单或使用Ajax删除它

   {{ Form::open(array('url' => 'shops/'. $row->id)) }}
                    {{ Form::hidden('_method', 'DELETE') }}
                    {{ Form::submit('Delete this User', array('class' => 'btn btn-warning')) }}
                {{ Form::close() }}
这是我的建议

更新

希望这对你有帮助

您可以像这样将$row->id传递给锚id属性

 <a class="btn btn-xs btn-danger" id="{{$row->Id}}" onclick="delete_user(this.id) return false;" href="#" rel="nofollow" >Delete this entry</a>

然后使用下面的脚本使用Destory方法

function delete_user(Id) {
var result = confirm("Want to delete?");
if (result==true) {
        $.ajax({
            url:'http://localhost:81/laravel/myapps/public/shops/'+Id,
            type:"Post",
            data: {'_method':'delete'},
            success:function($msg){
                alert($msg);
            }
        });
    }
    }
</script>
函数删除用户(Id){
var结果=确认(“是否要删除?”);
如果(结果==真){
$.ajax({
网址:'http://localhost:81/laravel/myapps/public/shops/“+Id,
类型:“Post”,
数据:{u方法:'delete'},
成功:函数($msg){
警报($msg);
}
});
}
}

您不能通过锚定标记href attr删除用户,您需要使用表单或使用Ajax删除它

   {{ Form::open(array('url' => 'shops/'. $row->id)) }}
                    {{ Form::hidden('_method', 'DELETE') }}
                    {{ Form::submit('Delete this User', array('class' => 'btn btn-warning')) }}
                {{ Form::close() }}
这是我的建议

更新

希望这对你有帮助

您可以像这样将$row->id传递给锚id属性

 <a class="btn btn-xs btn-danger" id="{{$row->Id}}" onclick="delete_user(this.id) return false;" href="#" rel="nofollow" >Delete this entry</a>

然后使用下面的脚本使用Destory方法

function delete_user(Id) {
var result = confirm("Want to delete?");
if (result==true) {
        $.ajax({
            url:'http://localhost:81/laravel/myapps/public/shops/'+Id,
            type:"Post",
            data: {'_method':'delete'},
            success:function($msg){
                alert($msg);
            }
        });
    }
    }
</script>
函数删除用户(Id){
var结果=确认(“是否要删除?”);
如果(结果==真){
$.ajax({
网址:'http://localhost:81/laravel/myapps/public/shops/“+Id,
类型:“Post”,
数据:{u方法:'delete'},
成功:函数($msg){
警报($msg);
}
});
}
}

它仍然重定向到show()。我想这是我已经用过的同一个例子。无论如何谢谢你。它仍然重定向到show()。我想这是我已经用过的同一个例子。无论如何谢谢你。这个链接在一个大表单中。因此,如果在主窗体内创建了另一个要删除的窗体,它将无法正常工作。此链接位于一个大窗体内。因此,如果在主窗体内创建了另一个要删除的窗体,则该窗体无法正常工作。