UserController::admin_store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use App\Models\User;
11
use App\Models\UserObyx;
12
use App\Models\UserRole;
13
use App\Models\UserOnline;
14
use Illuminate\Http\Request;
15
16
class UserController extends Controller
17
{
18
    public function index()
19
    {
20
        $user = User::orderBy('name')->paginate(25);
21
22
        $obyxmax = \DB::table('user_obyx as uo')
23
            ->leftJoin('obyx as o', 'o.id', '=', 'uo.obyx_id')
24
            ->selectRaw('SUM(o.value) as value')
25
            ->groupBy('uo.user_id')
26
            ->orderByRaw('SUM(o.value) DESC')
27
            ->first();
28
29
        return view('users.index', [
30
            'users'   => $user,
31
            'obyxmax' => $obyxmax,
32
        ]);
33
    }
34
35
    public function show($userid)
36
    {
37
        $user = User::whereId($userid)->first();
38
39
        $data = UserObyx::with('obyx', 'user')->orderBy('created_at', 'desc')->where('user_id', '=', $userid)->take(10)->get();
40
41
        return view('users.show', [
42
            'user' => $user,
43
            'obyx' => $data,
44
        ]);
45
    }
46
47
    public function admin($userid)
48
    {
49
        if (\Auth::check()) {
50
            if (\Auth::user()->settings->is_admin == 1) {
51
                $user = User::whereId($userid)->first();
52
53
                $perms = UserRole::all();
54
55
                return view('users.admin', [
56
                    'user'  => $user,
57
                    'perms' => $perms,
58
                ]);
59
            }
60
        }
61
    }
62
63
    public function admin_store(Request $request, $userid)
64
    {
65
        $role = UserRole::all()->where('id', '=', $request->get('perm'))->first();
66
        $user = User::find($userid);
67
68
        $user->detachRoles($user->roles);
69
        $user->attachRole($role);
70
71
        return redirect()->action('UserController@admin', [$userid]);
72
    }
73
74
    public function activity_index()
75
    {
76
        $data = UserObyx::with('obyx', 'user')->orderBy('created_at', 'desc')->paginate(25);
77
78
        return view('users.activity.index', [
79
            'obyx' => $data,
80
        ]);
81
    }
82
83
    public function users_online()
84
    {
85
        $uo = UserOnline::orderBy('created_at', 'desc')->get();
86
87
        return view('users.online', [
88
            'uo' => $uo,
89
        ]);
90
    }
91
}
92