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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀