Laravel form won't PATCH, only POST - nested RESTfull Controllers, MethodNotAllowedHttpException

前端 未结 4 1281
隐瞒了意图╮
隐瞒了意图╮ 2021-01-05 11:47

I am trying to allow users to edit their playlist. However, whenever I try to execute the PATCH request, I get the MethodNotAllowed

相关标签:
4条回答
  • 2021-01-05 12:23

    As suggested by @Michael A in the comment above, send it as a POST

    <form method="POST" action="patchlink">
         <input type="hidden" name="_method" value="PATCH">
    

    Worked for me.

    0 讨论(0)
  • 2021-01-05 12:25

    Since html forms support only GET and POST you need to add an extra hidden field to the form called _method in order to simulate a PATCH request

    <input type="hidden" name="_method" value="PATCH">
    
    0 讨论(0)
  • 2021-01-05 12:30

    Write {!! method_field('patch') !!} after form:

    <form method="POST" action="patchlink">
         {!! method_field('patch') !!}
         . . .
    </form>
    

    Official documentation for helper function method_field()

    0 讨论(0)
  • 2021-01-05 12:32

    In Laravel 5 and up:

    <form method="POST" action="patchlink">
        @method('patch')
        . . .
    </form>
    
    0 讨论(0)
提交回复
热议问题