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

38 lines
822 B
PHP
Raw Normal View History

2020-06-29 12:28:09 +00:00
<?php
namespace App\Http\Middleware;
use App\User;
use Closure;
2020-07-30 12:38:32 +00:00
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
2020-06-29 12:28:09 +00:00
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 */
2020-07-30 12:38:32 +00:00
$user = Auth::user();
2020-06-29 12:28:09 +00:00
if(!isset($user))
return redirect()->route("users.login");
if($user->hasAnyPermission($permissions)) {
return $next($request);
}
return redirect()->route("users.login");
}
}