ranks of users
This commit is contained in:
@@ -16,13 +16,24 @@ class RequireRole
|
||||
*/
|
||||
public function handle($request, Closure $next, $role)
|
||||
{
|
||||
$confirmed = false;
|
||||
$ranking = array([
|
||||
'None' => 0,
|
||||
'Guest' => 1,
|
||||
'User' => 2,
|
||||
'Admin' => 3,
|
||||
]);
|
||||
$check = DB::table('user_roles')->where('character_id', auth()->user()->character_id)->get(['role']);
|
||||
printf($check);
|
||||
printf($role);
|
||||
if($check === $role) {
|
||||
$confirmed = true;
|
||||
} else {
|
||||
$confirmed = false;
|
||||
foreach($ranking as $rank => $value) {
|
||||
if($role === $check['role']) {
|
||||
$confirmed = true;
|
||||
break;
|
||||
} else {
|
||||
if($rank[$check['role']] > $rank[$check['role']]) {
|
||||
$confirmed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abort_unless(auth()->check() && $confirmed, 403, "You don't have permissions to access this area!");
|
||||
|
||||
19
app/User.php
19
app/User.php
@@ -46,16 +46,15 @@ class User extends Authenticatable
|
||||
protected $guarded = [];
|
||||
|
||||
//Used in middleware to make sure a user is able to access many of the pages
|
||||
public function hasRole($role)
|
||||
{
|
||||
$check = User::role()->get(['role']);
|
||||
//dd($check);
|
||||
if($check == $role) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//public function hasRole($role)
|
||||
//{
|
||||
// $check = User::role()->get(['role']);
|
||||
// if($check == $role) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
public function getUserType() {
|
||||
return User::where('user_type')->get();
|
||||
|
||||
Reference in New Issue
Block a user