我想创建用户,我可以授予权限。 我创建了一个权限模型,其中包含以下属性(ID |名称|显示名|倒序)Laravel使Acl用户具有权限(无级别/组)
1|xyz.edit|Edit xyz| Allow to edit xyz
2|xyz.create|Create xyz| Allow to create xyz
因此,我要像下面创建关系:
public function getPermissions(){
return $this->hasMany('App\Permission');
}
但它不工作。有没有什么办法可以创建像 这样的关系用户有很多权限但是没有为用户创建相同的权限? 我可以让用户模型像id|pass|login|...|permissions
并与splited权限存储权限ID“”并在getPermissions()
功能做出这样的事情:
public function getPerms(){
foreach (explode($this->permssions,',')as $id){
//here load from database perm by id add to array and return
}
}
或第二选项我在本教程https://www.youtube.com/watch?v=Kas2w2DBuFg是让看另一个表像user_perms
与领域
id|user_id|perms|id
但什么选择是最好做到这一点?