Skip to content

Instantly share code, notes, and snippets.

@pengan1987
Created August 19, 2015 06:14
Show Gist options
  • Select an option

  • Save pengan1987/71780d33f497faf91c10 to your computer and use it in GitHub Desktop.

Select an option

Save pengan1987/71780d33f497faf91c10 to your computer and use it in GitHub Desktop.
Enter file contents here<?php namespace SleepingOwl\Admin\Http\Middleware;
use AdminAuth;
use Closure;
class AdminAuthenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (AdminAuth::guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest(route('admin.login'));
}
}
//in this example, I assume that in the table administrators is a flag "isAdmin",
//but you can change it to whatever you can
if (AdminAuth::user()->role < 10000) {
//here i check the current request path against the config definitions
$path = $request->path();
if ($path == "admin/users") {
return redirect()->intended(route('admin.wildcard', '/'));
}
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment