简体   繁体   中英

Extending one model with another model in Laravel

I am pretty new to laravel and currently exploring its concepts. In some videos I saw a concept of models inheritance. I wonder if we can use models relationships in laravel 5.6 then why we need to inherit models. In which case we need to or should inherit models.

eg Base Model:

class User extends Authenticatable
{

}

eg Child Model:

Class UserTypeOne extends User()
{
}

eg Child Model2:

Class UserTypeTwo extends User
{
}

Thanks in advance.

You don't really need to inherit Models like class inherit. You should use Eloquent Relationship instead. Prior to development, you have to do proper database designing.

https://laravel.com/docs/5.6/eloquent-relationships

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