Issues (404)

Branch: dev

app/Http/Middleware/CheckRole.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Facades\App\Services\WhichPortal;
7
use Illuminate\Support\Facades\Auth;
8
9
class CheckRole
10
{
11
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @param  \Closure  $next
17
     * @param  string  $role
18
     * @return mixed
19 15
     */
20
    public function handle($request, Closure $next, $role)
21
    {
22 15
        // If user logged in as admin, always pass, regardless of $role.
23 3
        if (Auth::check() && Auth::user()->isAdmin()) {
24 3
            return $next($request);
25
        }
26
27
        // Redirect if not logged in, or if not the correct role.
28 12
        if (Auth::guest() || !Auth::user()->hasRole($role)) {
29
            // TODO: redirect to some sort of error message.
30
            if (WhichPortal::isManagerPortal()) {
31
                return redirect(route('manager.home'));
0 ignored issues
show
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
                return /** @scrutinizer ignore-call */ redirect(route('manager.home'));
Loading history...
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
                return redirect(/** @scrutinizer ignore-call */ route('manager.home'));
Loading history...
32
            } elseif (WhichPortal::isHrPortal()) {
33
                return redirect(route('hr_advisor.home'));
34
            } else {
35
                return redirect(route('home'));
36
            }
37 12
        }
38
        return $next($request);
39
    }
40
}
41