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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器