UserBanController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Ban;
6
use App\Models\User;
7
use Illuminate\Http\Request;
8
9
class UserBanController extends Controller
10
{
11
    public function __construct()
12
    {
13
        $this->middleware('permission:admin-user');
14
    }
15
16
    public function show($userid)
17
    {
18
        $user = User::whereId($userid)->first();
19
20
        return view('users.ban.show', [
21
            'user' => $user,
22
        ]);
23
    }
24
25
    public function ban(Request $request, $userid)
26
    {
27
        $user = User::whereId($userid)->first();
28
29
        $exp = 0;
30
31
        if ($request->exists('forever')) {
32
            $exp = '+ 150 years';
33
        } elseif ($request->exists('aday')) {
34
            $exp = '+1 day';
35
        } elseif ($request->exists('aweek')) {
36
            $exp = '+1 week';
37
        } elseif ($request->exists('amonth')) {
38
            $exp = '+1 month';
39
        }
40
41
        $user->ban([
42
            'comment'    => $request->get('banreason'),
43
            'expired_at' => $exp,
44
        ]);
45
46
        return redirect(action('UserBanController@show', $userid));
47
    }
48
49
    public function unban(Request $request, $userid)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        $user = User::whereId($userid)->first();
52
53
        $user->unban();
54
55
        return redirect(action('UserBanController@show', $userid));
56
    }
57
}
58