-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuthServiceProvider.php
executable file
·54 lines (48 loc) · 1.44 KB
/
AuthServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace App\Providers;
use JamesMills\LaravelAdmin\Models\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)
{
parent::registerPolicies($gate);
try {
if (\Schema::hasTable('permissions')) {
// Dynamically register permissions with Laravel's Gate.
foreach ($this->getPermissions() as $permission) {
$gate->define($permission->name, function ($user) use ($permission) {
return $user->hasPermission($permission);
});
}
}
} catch (\Illuminate\Database\QueryException $ex) {
return;
}
}
/**
* Fetch the collection of site permissions.
*
* @return \Illuminate\Database\Eloquent\Collection
*/
protected function getPermissions()
{
return Permission::with('roles')->get();
}
}