From 40219e16838ea3897f30ad3ac8312634b9b60dcb Mon Sep 17 00:00:00 2001 From: IDStack Date: Sun, 11 Oct 2020 22:44:34 +0700 Subject: [PATCH] Implementasi Middleware Untuk Admin --- app/Http/Controllers/AttendanceController.php | 2 +- app/Http/Controllers/UserController.php | 2 +- app/Http/Kernel.php | 1 + app/Http/Middleware/IsAdmin.php | 24 +++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/Http/Middleware/IsAdmin.php diff --git a/app/Http/Controllers/AttendanceController.php b/app/Http/Controllers/AttendanceController.php index 4e6ea05..62b24ad 100644 --- a/app/Http/Controllers/AttendanceController.php +++ b/app/Http/Controllers/AttendanceController.php @@ -14,7 +14,7 @@ class AttendanceController extends Controller */ public function __construct() { - $this->middleware('auth'); + $this->middleware(['auth', 'is_admin']); } public function index(Request $request) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 16c0bd2..7354518 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -18,7 +18,7 @@ class UserController extends Controller */ public function __construct() { - $this->middleware('auth'); + $this->middleware(['auth', 'is_admin']); } /** diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 8fdf11b..880eece 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -65,5 +65,6 @@ class Kernel extends HttpKernel 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'is_admin' => \App\Http\Middleware\IsAdmin::class, ]; } diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php new file mode 100644 index 0000000..9083ad0 --- /dev/null +++ b/app/Http/Middleware/IsAdmin.php @@ -0,0 +1,24 @@ +user()->is_admin) { + return redirect('/home'); + } + + return $next($request); + } +}