1
여러 개의 관계가 정의 된 User
이라는 모델이 있다고 가정합니다 (role
및 permissions
). 내 사용자 모델에 직접 액세스 할 수있는 방법 컬렉션 또는 관련 권한 컬렉션?Laravel4 모델에서 관련 컬렉션을 얻는 방법
컨트롤러 :
내가 뭘하려고 오전if (Auth::user()->hasPermission('test'))
{ // code goes here}
을 내 모델 :
public function hasPermission($name)
{
$permission = \Permission::where('name', '=', $name)->get();
$list = ($this->overwrite_permission) ? $this->permissions : $this->role->permissions;
//here I want to have a collection to use contains()
if ($list->contains($permission))
{
return true;
}
return false;
}
클리너 용액 용. –