Created
May 8, 2020 13:18
-
-
Save nicolaskempf57/9277dd9c8f5d28fec9ad35bdc2a049df to your computer and use it in GitHub Desktop.
CheckRole file for my blog post on Laravel Middleware https://medium.com/blog-justenico/laravel-les-middlewares-59b651d80b10
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 CheckRole | |
{ | |
/** | |
* Handle the incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @param string $role | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next, $role) | |
{ | |
if (! $request->user()->hasRole($role)) { | |
// Redirect… | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment