Last active
September 6, 2015 19:21
-
-
Save martinbean/19c39154df37a8702132 to your computer and use it in GitHub Desktop.
Is administrator middleware for Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
class Administrator | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException | |
* @return mixed | |
*/ | |
public function handle(Request $request, Closure $next) | |
{ | |
if (! $request->user()->isAdministrator()) { | |
if ($request->ajax()) { | |
return response('Forbidden.', 403); | |
} else { | |
throw new AccessDeniedHttpException; | |
} | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment