id
parent_id // <--- this is the key.
name
...
/**
* this addional (and optional) attribute can help you to identify
* if this is the parent of the branch, because with
* this approach you can have grandchilds and so on..
**/
is_root // <---
然后在您的模型中: 用户.php
public function parent()
{
return $this->belongsTo(User::class, 'parent_id');
}
现在,关于用户类型,您还可以设置一个属性来了解用户类型:
id
parent_id
name
type // <-- this could show the user type: 'student', 'teacher', etc
1条答案
按热度按时间kxeu7u2r1#
好吧,要将一个类的对象链接到同一个类(a)的父对象,只需在属性中设置它:
students
表架构然后在您的模型中:
用户.php
现在,关于用户类型,您还可以设置一个属性来了解用户类型: