dongyu5104 2016-08-08 09:39
浏览 50
已采纳

Eloquent模型是否与MVC模型相同(在laravel中)?

I saw this post (The difference between an Eloquent Model and a Model?) but it doesn't explicitly answer the question for me.

I may not be using the right terminology here...

I understand Eloquent to be "...an ActiveRecord implementation for working with your database..." as it says in the documentation. But is what is not clear to me is difference between these eloquent models, and models as one refers to them in the MVC sense.

Does it sound logical if I was to say that in a particular laravel application

  1. there will be many models, some of which are Eloquent models, and some of which are models in the MVC sense.
  2. Eloquent models are quite lean and pure classes, allowing interaction with the database layer.
  3. MVC models, by comparison may contain all sorts of business rules & logic
  4. Both types are easily created by php artisan make:model although with an Eloquent model one might want to create the migration at the same time.
  5. All models are stored in the same place, unless otherwise organised. It's not as if there is some externally visible location or naming convention to indicate that this is an Eloquent Model, or a MVC model.

...is that about right?

  • 写回答

1条回答 默认 最新

  • downing1988 2016-08-08 09:48
    关注
    1. There are only models. Some of them have extended functionality by using the Object-relational mapping methodology - Eloquent ( one of many ).You can read more about ORM here:

    https://en.wikipedia.org/wiki/Object-relational_mapping

    1. They are everything but not lean and pure. They are far blown and use a lot of unnecessary data to create relations between database object in the form of easy to read / use syntax. Example firstModel->secondModel->thirdModel->somethingSilly();

    2. MVC Models can contain everything as Controller but they answer to convention so you should probably read more extensively about MVC and the logic behind it.

    3. Pretty much that's the purpose of Artisan. To make everything more simple and easy to use.

    4. Yep.

    If you need a bit more information I can provide you with answers and url in the comment below.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?