dounianluo0086 2013-07-18 15:17
浏览 58
已采纳

RESTful控制器,具有多种CRUD方法

This is something I don't understand quite well I making making an App for my self using Laravel and would like to upkeep to standards.

So I have the following:

class UserController extends BaseController {

    GET index(), show(), new(), edit()        
    POST create()
    PUT update()
    DELETE destroy()
}

class UserModel { hasMany->Assets }

class Asset { pulic function fetchAssetsFromApi(); }

Now I don't have an Asset controller because there is nothing about Asset that needs to be displayed on it's own. I simply have the model for the ORM purposes to represent assets table.

Now the Assets model has a method that pulls Assets associated with a particular User and adds them to the database.

Now my view that is rendered by UserController->show has a button called Update Assets that should call fechAssetsFromApi() to update characters assets. However since there is no way to invoke alone with a button I would have to POST to a controller.

Meaning now I would need to have another method in my UsersController since it's the only one that will be using Assets model.

Now my question is does this break rules and guidelines for RESTfull controllers ? I will have this similar dilema appear multiple time in application ho should i approach it.

Should a proper RESTFull controller contain only CRUD or ?

  • 写回答

1条回答 默认 最新

  • dongxi1879 2013-07-18 16:13
    关注

    As far as I know, having more functions in a controller is fine, but you should only have your public functions be your CRUD functions. In this case, I would just make a link that, when clicked, will just go back to the that same route. This means that the same show() function will be called, except anything that has been updated will now be pulled to the page. Essentially force a refresh of the browser page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘