You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Entities\Users\Permission;
|
|
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The policy mappings for the application.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $policies = [
|
|
'App\Model' => 'App\Policies\ModelPolicy',
|
|
];
|
|
|
|
/**
|
|
* Register any application authentication / authorization services.
|
|
*
|
|
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
|
|
* @return void
|
|
*/
|
|
public function boot(GateContract $gate)
|
|
{
|
|
$this->registerPolicies($gate);
|
|
|
|
// Dynamically register permissions with Laravel's Gate.
|
|
foreach ($this->getPermissions() as $permission) {
|
|
$gate->define($permission->name, function ($user) use ($permission) {
|
|
return $user->hasPermission($permission);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Fetch the collection of site permissions.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
*/
|
|
protected function getPermissions()
|
|
{
|
|
return Permission::with('roles')->get();
|
|
}
|
|
}
|