Skip to content

Instantly share code, notes, and snippets.

@nicolaskempf57
Created May 8, 2020 13:18
Show Gist options
  • Save nicolaskempf57/9277dd9c8f5d28fec9ad35bdc2a049df to your computer and use it in GitHub Desktop.
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
<?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