Skip to content

Instantly share code, notes, and snippets.

@yooouuri
Created January 28, 2017 14:45
Show Gist options
  • Select an option

  • Save yooouuri/f5d5992a04ebb6f9494196e8c928c8a5 to your computer and use it in GitHub Desktop.

Select an option

Save yooouuri/f5d5992a04ebb6f9494196e8c928c8a5 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use App\User;
use Closure;
use Illuminate\Support\Facades\Auth;
class CheckAdmin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
/** @var User $user */
$user = Auth::user();
if ($user->isAdmin()) {
return $next($request);
}
}
return response()
->redirectToRoute('admin');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment