1. 云栖社区>
  2. PHP教程>
  3. 正文

Jon LeMaitre: Separation of Concerns with Laravel’s Eloquent (Series)

作者:用户 来源:互联网 时间:2017-12-01 15:23:17

Jon LeMaitre: Separation of Concerns with Laravel’s Eloquent (Series) - 摘要: 本文讲的是Jon LeMaitre: Separation of Concerns with Laravel’s Eloquent (Series), Jon LeMaitrehas written up a series of posts talking about effective separation of concerns using Eloquent, the

Jon LeMaitrehas written up a series of posts talking about effective separation of concerns using Eloquent, the database access component of the Laravel framework. His goal is to show you how makes use of the library and keep your application both maintainable and readable.

Eloquent (and by extension, Laravel) is often criticized because of its ActiveRecord ORM implementation, and that DataMapper produces a cleaner, more maintainable architecture in the long run. [...] This combination of behaviors crammed into a single object in itself is not the problem (in fact, it’s a wonderful asset), the problem is in how you make use of those behaviors throughout your application. You can be sloppy with them, or you can be tidy with them.

He starts with the "sloppy approach" where different methods of accessing the objects (and their data) are spread all across the application. He counters this with the tidy approach that makes use of "persistence-agnostic 'POPOs'" to hide the logic behind repositories. In the second part of the serieshe starts in and puts this idea into practice, using a simple "Member" table and model and repository classes to abstract the logic. Finally, in part threehe gets into some more extended functionality for the repositories approach: handling collections, relations, eager loading and schema changes.

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索,以便于您获取更多的相关知识。