Add admin middleware

This commit is contained in:
Daniel Supernault 2018-05-19 20:58:45 -06:00
parent d8303e7de5
commit 05df1c6a5f
2 changed files with 25 additions and 0 deletions

View file

@ -51,6 +51,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $routeMiddleware = [
'admin' => \App\Http\Middleware\Admin::class,
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,

View file

@ -0,0 +1,24 @@
<?php
namespace App\Http\Middleware;
use Auth, Closure;
class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(Auth::check() == false || Auth::user()->is_admin == false) {
return redirect(config('app.url'));
}
return $next($request);
}
}