简体   繁体   English

Laravel中控制器和模型之间的Repositories层的优势在哪里

[英]Where is the advantages of Repositories layer between controllers and models in laravel

there is a Repositories layer in my laravel project.我的 Laravel 项目中有一个 Repositories 层。 I am a freshman about laravel.我是 Laravel 的大一新生。 I can not fully understand the advantages of this layer.我不能完全理解这一层的优点。 My colleagues tell me that it is purpose to lower the coupling of the codes.我的同事告诉我,目的是降低代码的耦合度。 Obviously, it is true.显然,这是真的。 But I also look forward to your comments.但我也期待您的评论。

Using repositories, we can create complicated query and isolated it behind a readable method name.使用存储库,我们可以创建复杂的查询并将其隔离在可读的方法名称后面。 The coupled used, when using eloquent, we must put the record name in eloquent query, but using repositories, we can hide the record name and put in the other place.耦合使用,在使用eloquent的时候,一定要把记录名放在eloquent query中,但是使用repositories,我们可以把记录名隐藏起来放到别的地方。 So that is give some security reason too.所以这也给出了一些安全理由。 Also we can use for grouped some entities for authoritative users.我们也可以用于为权威用户分组一些实体。 Repository allows abstraction from data provide engine.存储库允许从数据提供引擎中进行抽象。

This article can help you. 这篇文章可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM