Created
July 1, 2016 18:48
-
-
Save peterquentin/7c7fbe49b9f2d34ab20f0b2b2b50c84a to your computer and use it in GitHub Desktop.
Sample RoleMiddleware
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; | |
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