Issues (84)

app/Http/Middleware/CheckAssociation.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Bouncer;
0 ignored issues
show
The type Bouncer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Closure;
7
use App\Association;
8
use Illuminate\Support\Arr;
9
10
class CheckAssociation
11
{
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @param  \Closure  $next
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next)
20
    {
21
        $association = $request->route('association');
22
23
        if (!($association instanceof Association)) {
24
            // FIXME: redo routes so we always get association from there instead:
25
            $subdomain = Arr::first(explode('.', $request->getHost()));
26
27
            $association = Association::where('subdomain', $subdomain)->first();
28
        }
29
30
        if (Bouncer::can('manage', $association)) {
31
            return $next($request);
32
        }
33
        else {
34
            return redirect()->route('admin');
35
        }
36
    }
37
}
38