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

32 lines
619 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
* @return mixed
*/
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");
}
}