Skip to content

Instantly share code, notes, and snippets.

@andreoav
Last active October 30, 2015 12:39
Show Gist options
  • Save andreoav/731d30ead14ad91ea5b5 to your computer and use it in GitHub Desktop.
Save andreoav/731d30ead14ad91ea5b5 to your computer and use it in GitHub Desktop.
Defender + Laravel ACL Integration - Role Permissions
<?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