dongpai9986 2015-01-26 18:15
浏览 47
已采纳

Laravel在创建模型时扩展了Eloquent

When creating a basic model in Laravel, I extend the Eloquent class so that my model has all of the awesome Eloquent functionality. For example:

class Product extends \Eloquent {
    //class definition here
}

I've been reading through the Laravel framework source code, and I don't understand where this Eloquent class actually comes from. I can see there is a Illuminate\Database\Eloquent\Model class, which seems to have all of the functionality I would expect from the Eloquent class that I'm extending, but I'm confused how the inheritance is actually working since I'm extending Eloquent , not Illuminate\Database\Eloquent\Model.

How does this work?

  • 写回答

1条回答 默认 最新

  • dongzi0850 2015-01-26 18:22
    关注

    If you look at the contents of the file "config/app.php", you will find an "aliases" key towards the bottom of the file. That is what is doing all the magic under the hood. Laravel allows you to alias classes and you can add yours too to the "config/app.php" file so that you do not have to use long, fully qualified names in your code everywhere.

    As you can see, the actual class that you are extending is "Illuminate\Database\Eloquent\Model" which is aliased to "Eloquent" hence you only need to extend "Eloquent".

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

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?