laravel extends Model == extends Eloquent?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31837869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:07:36  来源:igfitidea点击:

extends Model == extends Eloquent?

laravellaravel-4laravel-5

提问by Jonathan Solorzano

All the examples of Eloquent Models in Laravel 4 extends Eloquent, but when you generate a Model in Laravel 5 it says extends Model, are they the same?

Laravel 4 中 Eloquent 模型的所有例子都扩展了 Eloquent,但是当你在 Laravel 5 中生成一个模型时,它说扩展模型,它们是一样的吗?

Laravel 4

Laravel 4

<?php

class User extends Eloquent {

    //Code

}

Laravel 5

Laravel 5

<?php

class User extends Model {

    //Code

}

The Laravel 5 docssays:

Laravel 5文档说:

Defining An Eloquent Model

class User extends Model {}

定义 Eloquent 模型

class User extends Model {}

回答by Patrick Stephan

Yes they are the same. Laravel 4 uses Class Aliasing to map Illuminate\Database\Eloquent\Modelto Eloquent. You can see in the app/config/app.phpfile:

是的,它们是一样的。Laravel 4 使用类别名映射Illuminate\Database\Eloquent\ModelEloquent. 你可以在app/config/app.php文件中看到:

'Eloquent'          => 'Illuminate\Database\Eloquent\Model',

Laravel 5 uses namespacing instead. So at the top of the model class you will see this line:

Laravel 5 使用命名空间代替。所以在模型类的顶部你会看到这一行:

use Illuminate\Database\Eloquent\Model;

回答by Kevin Damian Cifuentes Munera

used...

用过的...

use Illuminate\Database\Eloquent\Model;

to extend the model

扩展模型

回答by redestructa

I am using the _ide_helper.php file from barryvdh's laravel-ide-helper

我正在使用 barryvdh 的 laravel-ide-helper 中的 _ide_helper.php 文件

The subclass there is also called Eloquent and extends to Model.

那里的子类也称为 Eloquent 并扩展到 Model。

So if I extend my own model class to Eloquent, the IDE knows all the functions, like MyModelClass::find. Maybe there's another way to do it, but that really works for me.

因此,如果我将自己的模型类扩展到 Eloquent,IDE 会知道所有函数,例如 MyModelClass::find。也许有另一种方法可以做到这一点,但这对我来说确实有效。