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

34 lines
668 B
PHP
Raw Normal View History

2020-06-29 12:28:09 +00:00
<?php
namespace App\Http\Middleware;
use App\User;
use Closure;
class CheckAuth
{
/**
* Handle an incoming request.
*
2020-07-27 08:20:29 +00:00
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param $permissions
2020-06-29 12:28:09 +00:00
* @return mixed
2020-07-27 08:20:29 +00:00
* @throws \Exception
2020-06-29 12:28:09 +00:00
*/
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");
}
}