douxin2002 2015-07-07 02:21
浏览 55
已采纳

如何让我的资源控制器触发destroy _method?

I am having a problem with the laravel5 resource controller. The POST method is working fine however the delete method is not. as you can see from postman i am passing the DELETE _method to the correct route

postman screen capture In the mean time i am using direct routes which are also working fine.

Route::delete('customisemymeal', ['as'=>'customisemymeal', 'uses'=>'UserMealCustomController@destroy']);
Route::post('customisemymeal', ['as'=>'customisemymeal', 'uses'=>'UserMealCustomController@store']);

I have disabled the CSRF token check until this is sorted out.

Can you please help explain why the same method is different for a resource controller compared to a route::delete?

routes:list

  | DELETE                         | customisemymeal/{customisemymeal}                                       | customisemymeal.destroy            | App\Http\Controllers\UserMealCustomController@destroy         |

     | DELETE                         | customisemymeal                                       | customisemymeal           | App\Http\Controllers\UserMealCustomController@destroy         |
  • 写回答

1条回答 默认 最新

  • dongzhong2674 2015-07-07 02:52
    关注

    To use the route:

    Route::resource('customisemymeal', ['as'=>'customisemymeal', 'uses'=>'UserMealCustomController']);
    

    You must abide to a few rules. To delete something you need to use:

    domain.com/customisemymeal/resource_id
    

    From your screenshots you are trying to delete a resource, using a different URI.

    domain.com/customisemymeal
    

    That won't work.

    Rules are:

    Index:
    GET -> domain.com/resource
    
    Show:
    GET -> domain.com/resource/resource_id
    
    create:
    GET -> domain.com/resource/create
    
    edit:
    GET -> domain.com/resource/resource_id/edit
    
    update:
    PATCH / UPDATE -> domain.com/resource/resource_id
    
    store:
    POST -> domain.com/resource
    
    delete:
    DELETE -> domain.com/resource/resource_id
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统