Ekapp/skolehjem/app/Http/Middleware/CheckAuth.php

34 lines
668 B
PHP

<?php
namespace App\Http\Middleware;
use App\User;
use Closure;
class CheckAuth
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $permissions
* @return mixed
* @throws \Exception
*/
public function handle($request, Closure $next, $permissions)
{
/** @var User $user */
$user = $request->user();
if(!isset($user))
return redirect()->route("users.login");
if($user->hasAnyPermission($permissions)) {
return $next($request);
}
return redirect()->route("users.login");
}
}