【问题标题】:laravel 5.6 destroy functionlaravel 5.6 销毁函数
【发布时间】:2018-06-23 08:12:04
【问题描述】:

问题是当我尝试按下它应该指示我销毁控制器中的功能的按钮时,它以某种方式指示我显示功能

我使用 method = delete 和 route = posts.destroy

                  <tbody>
                          @foreach($MyPosts as $post)
                          <tr>
                            <th scope="row">1</th>
                            <td>{{$post->subject}}</td>
                            <td>{{$post->created_at->toDateString()}}</td>
                            <form method="delete" action="{{route('posts.destroy', $post->id)}}"> 
                            <td> <input class="btn btn-danger"  value="DELETE" type="submit" style="width:100px"></td>
                            </form>
                            @csrf
                            <td><a href="{{route('posts.edit',  $post->id)}}"><input type="submit" class="btn btn-warning" value="edit"></a> </td>
                          </tr>
                          @endforeach
                       </tbody>

路由文件

   Route::get('/Testing', 'ViewsController@getTest');
   Route::get('/contact', 'ViewsController@getcontact');
   Route::get('/about', 'ViewsController@getabout');
   Route::get('/', 'ViewsController@getIndex');
   Route::resource('/posts','PostController');


  public function show($id)
{
        $post = Post::find($id);
        dd($post);
        return view('posts.show')->with('posts',$post);
}


public function destroy($id)
{   
    return('destroy');
}

【问题讨论】:

    标签: php forms laravel-5


    【解决方案1】:

    表单方法应该是POST并使用method_field helper:

    <td>
    <form method="POST" action="{{route('posts.destroy', $post->id)}}"> 
    @csrf 
    {{ method_field('DELETE') }} 
    <input class="btn btn-danger"  value="DELETE" type="submit" style="width:100px">
    </form>
    </td>
    

    【讨论】:

      猜你喜欢
      • 2019-07-29
      • 2016-08-09
      • 1970-01-01
      • 2023-01-13
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      相关资源
      最近更新 更多