condorrocks/condor

View on GitHub
app/Http/Middleware/RoleMiddleware.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\RedirectResponse;

class RoleMiddleware
{
    /**
     * Run the request filter.
     *
     * @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)) {
            return new RedirectResponse(url('/'));
        }

        return $next($request);
    }
}