我想創建用戶,我可以授予權限。 我創建了一個權限模型,其中包含以下屬性(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
但什麼選擇是最好做到這一點?