Latest

Thursday, July 13, 2017

Laravel resource controller destroy

Asked by: Brad Goldsmith


I'm having trouble using the destroy method from my resource controller. I know in html you can only POST/GET so I used a hidden value but it comes up with a MethodNotAllowedHttpException error. Here is my code:

Modal where the Delete Button is:

          <div class="modal-footer">
            <form action="/wod/{{$wod->id}}" method="POST">
                {{ csrf_field() }}
                {{ method_field('DELTE') }}
                <button type="button" class="btn btn-default navbar-inverse" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-default navbar-inverse"><a class="bottom" href="/wod/{{$wod->id}}/edit">Edit</a></button>
                <button class="btn btn-primary navbar-inverse" value="submit" type="submit">Delete</button>
            </form>
          </div>

And here is my resource controller:

public function destroy(Id $id)
{
    //
    Wod::find($id)->delete();

    return redirect()->action("WodController@index");

}


Source

No comments:

Post a Comment

Adbox