Skip to content

Instantly share code, notes, and snippets.

@martinbean
Last active September 6, 2015 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbean/19c39154df37a8702132 to your computer and use it in GitHub Desktop.
Save martinbean/19c39154df37a8702132 to your computer and use it in GitHub Desktop.
Is administrator middleware for Laravel
<?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