雄辩模型与模型之间的区别? [英] The difference between an Eloquent Model and a Model?

查看:109
本文介绍了雄辩模型与模型之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我很困惑:
在Laravel的官方文档中,他们说:


雄辩的ORM包括Laravel为您的数据库提供了一个漂亮简单的
ActiveRecord实现。每个
数据库表有一个相应的模型,用于与
与该表进行交互。


Ok这里的所有都是伟大的,我得到它!



所以我进行迁移创建一个数据库: php artisan make:migration create_items_table --create =items



很棒,直到这里也是:)



所以理论上来说,当我会做: php artisan make:model Item ,Laravel将创建一个php类(用于与items表进行交互):

  class Item extends Enloquent { 

...

}

但是在现实世界中,当我做: php artisan make:model Item ,Laravel创建php类(用于与items表进行交互)::

  class Item extends Model {

...

}
/ pre>

那么为什么模特而不是雄辩?我失踪了吗
和雄辩的模特与模特有什么区别。



如果有差别,我什么时候应该使用雄辩和模型? >

谢谢^^

解决方案

我找到了我的问题的解决方案



所以通常你必须添加一个别名到你的config / app.php

 'aliases'=> [
'Eloquent'=> Illuminate\Database\Eloquent\Model :: class,

当您创建模型时, Laravel将使用Eloquent; 而不是使用Illuminate\Database\Eloquent\Model; 这是为什么我认为,有些人可能会使用模型,当其他人可能使用雄辩,这只是一个对命名空间有意义的问题:3


So, i'm confused with this : In Laravel's official documentation, they say :

The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table.

Ok util here all is Great, i get it !

So I make a migration to create a database : php artisan make:migration create_items_table --create="items"

Great until here too :)

So theoretically speaking, when i will make : php artisan make:model Item , Laravel will create a php class ( which is used to interact with items table) :

   class Item extends Eloquent {

     ...

    }

But,in real world, when i make : php artisan make:model Item , Laravel creates php class ( which is used to interact with items table) ::

   class Item extends Model {

     ...

    }

So Why Model and not Eloquent ?? Am i missing sth ? And What's the difference between Eloquent Model and Model.

And if there's a difference, when should i use Eloquent and when Model ... ?

Thank you ^^

解决方案

I found the solution for my question ...

So Normally you must add an alias to your config/app.php

 'aliases' => [
        'Eloquent'  => Illuminate\Database\Eloquent\Model::class,

And when you create a model, Laravel will use Eloquent; instead of use Illuminate\Database\Eloquent\Model; this why i think, some person may use Model, when other may use Eloquent , it's just a matter of give a meaning sense to the namespace :3

这篇关于雄辩模型与模型之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆