Laravel删除按钮不起作用

时间:2017-06-23 15:22:36

标签: laravel-5 laravel-form

我想知道是否有人可以查看此代码并告诉我它为什么不起作用。当我按下提交按钮时,它将不会提交。

 {!! 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');

});

1 个答案:

答案 0 :(得分:-1)

更改

{!! Form::open([
 'method' => 'DELETE',
 'route' => ['posts.destroy', $post->id],
 'style' => 'display: inline'
 ]) !!}

 {!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}

{!! Form::open([
 'method' => 'DELETE',
 'route' => ['admin.posts.destroy', $post->id],
 'style' => 'display: inline'
  ]) !!}

 {!! Form::submit('Delete this post?', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}  

在路线中加上你的前缀。希望它会有所帮助