Skip to content

Commit

Permalink
Implementasi Middleware Untuk Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
IDStack authored and IDStack committed Oct 11, 2020
1 parent 68d1b16 commit 40219e1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AttendanceController extends Controller
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware(['auth', 'is_admin']);
}

public function index(Request $request)
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserController extends Controller
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware(['auth', 'is_admin']);
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/IsAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Closure;

class IsAdmin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! $request->user()->is_admin) {
return redirect('/home');
}

return $next($request);
}
}

0 comments on commit 40219e1

Please sign in to comment.