doushi5752 2016-07-24 22:00
浏览 11

限制路径允许的方法

I'm trying to remove the PUT method on one of my controllers, but I cannot find a way to do so without going through and mapping each method to a function.

I have the following in my route file:

Route::group(['prefix' => 'api'], function() {
    $defaultOptions = ['except' => ['create', 'edit']];

    Route::resource('recipies', 'RecipieController', $defaultOptions);
    //This is the one that I am trying to restrict
    Route::resource('recipies.ingredients', 'Recipie\IngredientController', ['except' => ['create', 'edit', 'show']]); 

    Route::resource('ingredients', 'IngredientController', $defaultOptions);
});

I know that I can do the following to accomplish what I am wanting, but I am hoping that there is some option where I can limit what methods are allowed

Route::get('recipies/{recipie_id}/ingredients', 'Recipie\IngredientController');
Route::patch('recipies/{recipie_id}/ingredients/{ingredient_id}', 'Recipie\IngredientController');
Route::delete('recipies/{recipie_id}/ingredients/{ingredient_id}', 'Recipie\IngredientController');

While the above will work, I feel that it is messy and am hoping for a cleaner solution.

  • 写回答

1条回答 默认 最新

  • dongshi1868 2016-07-25 09:27
    关注

    PUT method is mapped to update method of a resource controller. Add this method to the list of excluded methods:

    Route::resource('recipies.ingredients', 'Recipie\IngredientController', ['except' => ['create', 'edit', 'show', 'update]]); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用