Laravel API, how to accept DELETE method

后端 未结 3 1328
温柔的废话
温柔的废话 2021-01-29 00:08

I need to use my API to delete some entities, I create my controller, my methods, the routes. They works fine, all the get and put/patch method works, but with the delete one I

相关标签:
3条回答
  • 2021-01-29 00:48

    When you are posting to the Delete url, make sure you have this data in your post request:

    _method=delete
    

    this is just like an input field e.g:

    <input type="hidden" name="_method" value="delete">
    
    0 讨论(0)
  • 2021-01-29 01:03

    try this package CORS Middleware for Laravel 5

    0 讨论(0)
  • 2021-01-29 01:10

    Method not allowed is an HTTP Status code 405, and it usually translates to the lack of HTTP Verb matching that endpoint

    Edit: Also, check this

    e.g.

    All of these SHOULD mean different things and DO different things. If you make a Request to the last url but the url isn't registered (on your routes files or wherever you place them), then that's the error it returns because it matches the name but not the verb

    POST   url.com/user
    
    GET    url.com/user
    
    PUT    url.com/user
    
    PATCH  url.com/user
    
    DELETE url.com/user
    
    0 讨论(0)
提交回复
热议问题