dplase3140 2014-07-28 11:18
浏览 25

Laravel - '存储库模式'问题

Using Laravel 4, I currently have an area for all of my repositories, and then I bind these repositories to an interface to use. This is all currently working and I access these in my controllers using the standard $this->users->find(1) method.

In my User repository, I have my assignRole (attach) and removeRole (detach) methods which I took my my model/User.php class. Okay great, but now I try to run my seeds it uses the eloquent classes, e.g. User::create();.

Question 1: Are my seed files also supposed to also use the repository pattern? I have no experience with say Mongo, but would I also seed the database the same way if I were going to switch?

Question 2: My Auth driver currently uses eloquent... so what if I also changed this? Should I be making a repository for my auth and implement things like $this->auth->login($user).

Really I'm confused as to when I should be implementing a repository interface. artisan migrate runs the seed files, which currently create a MySQL DB, what would happen if I wanted to use Mongo or a NoSQL DB?

  • 写回答

2条回答 默认 最新

  • doulei2100 2014-07-28 11:32
    关注

    good questions.

    The short answer to each of your questions is "it depends".

    With your seeds - if you're sticking to the pattern strictly, then yes, your seeds should probably use the repository pattern. For me, however - my seeds tend to be for a quick, one-off database population and/or for testing purposes, so using Eloquent for this is probably okay.

    With your Auth driver, again, if you want to stick strictly to the pattern, then yes, you should probably code to an interface - but ask yourself whether or not you're really going to change your Auth implementation in the future - and whether the extra work/cost is really worth it.

    Each project is unique in requirements, budget and particularly the likelihood of change after it goes live. You just need to assess these factors and decide the best approach for each project.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog