Laravel 5 Laravel删除按钮不工作
我想知道是否有人可以看看这个代码,告诉我为什么它不工作。当我按下提交按钮时,它不会提交Laravel 5 Laravel删除按钮不工作,laravel-5,laravel-form,Laravel 5,Laravel Form,我想知道是否有人可以看看这个代码,告诉我为什么它不工作。当我按下提交按钮时,它不会提交 {!! Form::open([ 'method' => 'DELETE', 'route' => ['posts.destroy', $post->id], 'style' => 'display: inline' ]) !!} {!! Form::submit('Delete this post?', ['class' => 'btn
{!! Form::open([
'method' => 'DELETE',
'route' => ['posts.destroy', $post->id],
'style' => 'display: inline'
]) !!}
{!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
我将它提交给PostController的destory方法,其中路由被定义为“posts”
路由文件
Route::group(['prefix' => 'admin'], function() {
Route::resource('posts', 'PostController');
})) 变化
{!! Form::open([
'method' => 'DELETE',
'route' => ['posts.destroy', $post->id],
'style' => 'display: inline'
]) !!}
{!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
到
在路线中跟随您的前缀。希望这会有帮助将
'method'=>'DELETE'
更改为'method'=>'POST'
@LarsMertens为什么你认为这会有帮助?我刚刚测试了你的代码,它很好,而且正在工作here@behz4d我正要回答同样的问题。我的评论只是猜测而已Kaley36
您的代码很好,发生了上面示例中未定义的其他情况。我唯一能想到的是admin.posts.destroy
,如果不是这样的话,我们需要更多的信息。即使是无效的路由,它仍然应该发布,虽然这是错误的,但他使用的是Laravel HTML collective,它会自动为'method'=>'DELETE',
生成隐藏字段,所以他不需要再次使用{{Form::hidden('u method','DELETE')}
,当使用laravel HTML collective和类似DELETE
的方法时,它会自动出现在那里,但我不确定发生了什么,但我清除了缓存并重写了表单,现在它可以工作了,尽管它的代码相同。
{!! Form::open([
'method' => 'DELETE',
'route' => ['admin.posts.destroy', $post->id],
'style' => 'display: inline'
]) !!}
{!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}