added role in the user database added new function hasRole in user model added new function getUserType in user model modified registration to handle new column in user model
71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
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 authentication / authorization services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot(GateContract $gate)
|
|
{
|
|
$this->registerPolicies($gate);
|
|
|
|
$gate->define('isSuperAdmin', function($user) {
|
|
return $user->hasRole('SuperAdmin') == 'SuperAdmin';
|
|
});
|
|
|
|
$gate->define('isAdmin', function($user) {
|
|
return $user->hasRole('Admin') == 'Admin';
|
|
});
|
|
|
|
$gate->define('isUser', function($user) {
|
|
return $user->hasRole('User') == 'User';
|
|
});
|
|
|
|
$gate->define('isLegacy', function($user) {
|
|
return $user->hasRole('Legacy') == 'Legacy';
|
|
});
|
|
|
|
$gate->define('isGuest', function($user) {
|
|
return $user->hasRole('Guest') == 'Guest';
|
|
});
|
|
/*
|
|
$gate->define('isSuperAdmin', function($user) {
|
|
return $user->user_type == 'SuperAdmin';
|
|
});
|
|
|
|
$gate->define('isAdmin', function($user) {
|
|
return $user->user_type == 'Admin';
|
|
});
|
|
|
|
$gate->define('isW4RP', function($user) {
|
|
return $user->user_type == 'W4RP';
|
|
});
|
|
|
|
$gate->define('isLegacy', function($user) {
|
|
return $user->user_type == 'Legacy';
|
|
});
|
|
|
|
$gate->define('isGuest', function($user) {
|
|
return $user->user_type == 'Guest';
|
|
});
|
|
*/
|
|
}
|
|
}
|