简体   繁体   English

Laravel 4-User_detail模型

[英]Laravel 4 - User_detail Model

I have a User model which extends Eloquent which gets the data from the users table in my database. 我有一个扩展EloquentUser模型,该模型从数据库中的users表中获取数据。

The users table has the login details and a bunch of other data. users表包含登录详细信息和许多其他数据。 Now I want to create a user_details table which has even more details about a user such as address and contact info. 现在,我想创建一个user_details表,其中包含有关用户的更多详细信息,例如地址和联系信息。

Do I create another model class called User_detail and make this class extend the User class? 我是否要创建另一个名为User_detail模型类,并使该类扩展User类? I'm not sure how to collaborate the two models if that is the correct way of saying it. 如果这是正确的说法,我不确定如何将这两个模型进行协作。

Yes use a one to many relation in your User model... 是的,在您的用户模型中使用一对多关系...

http://laravel.com/docs/eloquent#one-to-many http://laravel.com/docs/eloquent#one-to-many

In your User class... 在您的User类中...

public function details() {
    return $this->hasMany('UserDetail');
}

You would call it like... 你会这样称呼...

foreach (User::find(1)->details as $row) {

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM