简体   繁体   中英

Laravel 4 - User_detail Model

I have a User model which extends Eloquent which gets the data from the users table in my database.

The users table has the login details and a bunch of other data. Now I want to create a user_details table which has even more details about a user such as address and contact info.

Do I create another model class called User_detail and make this class extend the User class? 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

In your User class...

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

You would call it like...

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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