Passed
Push — master ( b831b6...96f132 )
by John
06:04 queued 21s
created

Banned::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 8
nc 2
nop 2
dl 0
loc 12
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Http\Middleware\Group;
4
5
use App\Models\Eloquent\Group;
6
use Closure;
7
use Auth;
8
9
class Banned
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @param  \Closure  $next
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        $gcode = $request->gcode;
21
        $group = Group::where('gcode',$gcode)->first();
22
        $banneds = $group->banneds()->where('removed_at','>',date('Y-m-d H:i:s'))->first();
23
        $user = Auth::user();
24
        if(!empty($banneds) && $user->id != $group->leader->id) {
25
            return response()->view('errors.451',[
26
                'description' => 'This group is currently banned. Please contact the group administrator.'
27
            ]);
28
        }
29
        return $next($request);
30
    }
31
}
32