Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Created March 15, 2018 00:55
Show Gist options
  • Save wichaksono/f47bc3b960bae95ad6526e0137a66f49 to your computer and use it in GitHub Desktop.
Save wichaksono/f47bc3b960bae95ad6526e0137a66f49 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
class RoleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $roleName)
{
if(! $request->user()->hasRole($roleName))
{
return redirect()
->to('home');
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment