added remove role function
added add role function modified admin dashboard views
This commit is contained in:
54
app/Http/Controllers/AdminController.php
Normal file
54
app/Http/Controllers/AdminController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use DB;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('roles:Admin');
|
||||
}
|
||||
|
||||
public function displayDashboard() {
|
||||
return view('admin.dashboard');
|
||||
}
|
||||
|
||||
public function addRole(Request $request) {
|
||||
//Get the user and role from the form
|
||||
$user = $request->user;
|
||||
$role = $request->role;
|
||||
//Get the character id from the username using the user table
|
||||
$character = DB::table('users')->where('name', $user)->first();
|
||||
$check = DB::table('user_roles')->where(['character_id' => $character->character_id, 'role' => $role])->get();
|
||||
if($check === null) {
|
||||
DB::table('user_roles')->insert([
|
||||
'character_id' => $characer->character->id,
|
||||
'role'=> $role,
|
||||
]);
|
||||
return view('admin.dashboard')->with('success', 'User Updated.');
|
||||
}
|
||||
|
||||
return view('admin.dashboard')->with('error', 'User already has the role.');
|
||||
}
|
||||
|
||||
public function removeRole(Request $request) {
|
||||
//Get the user and role from the form
|
||||
$user = $request->user;
|
||||
$role = $request->role;
|
||||
//Get the character id from teh username using the user table
|
||||
$character = DB::table('users')->where('name', $user)->first();
|
||||
$check = DB::table('user_roles')->where(['character_id' => $character->character_id, 'role' => $role])->get();
|
||||
if($check !== null) {
|
||||
DB::table('user_roles')->where(['character_id' => $character->id,
|
||||
'role' => $role])
|
||||
->delete();
|
||||
return view('admin.dashboard')->with('success', 'User Updated.');
|
||||
}
|
||||
|
||||
return view('admin.dashboard')->with('error', 'User did not have the role.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user