cleanup and optimization
This commit is contained in:
@@ -23,16 +23,15 @@ class AdminController extends Controller
|
|||||||
$role = $request->role;
|
$role = $request->role;
|
||||||
//Get the character id from the username using the user table
|
//Get the character id from the username using the user table
|
||||||
$character = DB::table('users')->where('name', $user)->first();
|
$character = DB::table('users')->where('name', $user)->first();
|
||||||
$check = DB::table('user_roles')->where(['character_id' => $character->character_id, 'role' => $role])->get();
|
//Delete the current roles from the database
|
||||||
if($check === null) {
|
DB::table('user_roles')->where(['character_id' => $character->character_id])->delete();
|
||||||
DB::table('user_roles')->insert([
|
//Insert the new role into the database
|
||||||
'character_id' => $characer->character->id,
|
DB::table('user_roles')->insert([
|
||||||
'role'=> $role,
|
'character_id' => $characer->character->id,
|
||||||
]);
|
'role'=> $role,
|
||||||
return view('admin.dashboard')->with('success', 'User Updated.');
|
]);
|
||||||
}
|
//Return the view and the message of user updated
|
||||||
|
return view('admin.dashboard')->with('success', 'User Updated.');
|
||||||
return view('admin.dashboard')->with('error', 'User already has the role.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeRole(Request $request) {
|
public function removeRole(Request $request) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register any authentication / authorization services.
|
* Register any authentication / authorization services.
|
||||||
|
* These gates will always choose the highest roles
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -45,27 +46,5 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
$gate->define('isNone', function($user) {
|
$gate->define('isNone', function($user) {
|
||||||
return $user->hasRole('None');
|
return $user->hasRole('None');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
$gate->define('isSuperAdmin', function($user) {
|
|
||||||
return $user->role == 'SuperAdmin';
|
|
||||||
});
|
|
||||||
|
|
||||||
$gate->define('isAdmin', function($user) {
|
|
||||||
return $user->role == 'Admin';
|
|
||||||
});
|
|
||||||
|
|
||||||
$gate->define('isUser', function($user) {
|
|
||||||
return $user->role == 'User';
|
|
||||||
});
|
|
||||||
|
|
||||||
$gate->define('isGuest', function($user) {
|
|
||||||
return $user->role == 'Guest';
|
|
||||||
});
|
|
||||||
|
|
||||||
$gate->define('isNone', function($user) {
|
|
||||||
return $user->role == 'None';
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user