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 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: