Forked from peterquentin/gist:7c7fbe49b9f2d34ab20f0b2b2b50c84a
Created
July 2, 2016 04:02
-
-
Save drbyte/c1add7770029b6ddaf9347e79f2438e3 to your computer and use it in GitHub Desktop.
Sample RoleMiddleware
This file contains hidden or 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; | |
class RoleMiddleware | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @param string $role | |
* @param string $permission | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, $role, $permission) | |
{ | |
if (! $request->user()->hasRole($role) || ! $request->user()->can($permission)) { | |
abort(403); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment