Conditions | 4 |
Paths | 3 |
Total Lines | 19 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function handle($request, $next) |
||
17 | { |
||
18 | $route = app('router')->getRoutes()->match($request); |
||
19 | $contest = $route->parameter('contest'); |
||
20 | |||
21 | /** @var \App\Entities\Contest $contest */ |
||
22 | $contest = app(ContestRepository::class)->findOrFail($contest); |
||
23 | |||
24 | if (! $contest->isAvailable()) { |
||
25 | return back()->withErrors('Contest not found!'); |
||
26 | } |
||
27 | |||
28 | if ($contest->isPublic() || can_attend($contest)) { |
||
29 | return $next($request); |
||
30 | } |
||
31 | |||
32 | $errorMessage = 'You do not have privilege access contest '.$contest->id; |
||
33 | |||
34 | return redirect(route('contest.index'))->withErrors($errorMessage); |
||
35 | } |
||
37 |