Last active
October 30, 2015 12:39
-
-
Save andreoav/731d30ead14ad91ea5b5 to your computer and use it in GitHub Desktop.
Defender + Laravel ACL Integration - Role Permissions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register any application authentication / authorization services. | |
* | |
* @param \Illuminate\Contracts\Auth\Access\Gate $gate | |
* @return void | |
*/ | |
public function boot(GateContract $gate) | |
{ | |
$this->registerPolicies($gate); | |
foreach ($this->getPermissions() as $permission) { | |
$gate->define($permission->name, function ($user) use ($permission) { | |
return $user->hasRoles($permission->roles->pluck('name')->all()); | |
}); | |
} | |
} | |
/** | |
* Busca todas as permissões e os respectivos grupos. | |
* | |
* @return \Illuminate\Database\Eloquent\Collection | |
*/ | |
public function getPermissions() | |
{ | |
return app()['defender.permission']->make(['roles'])->get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment