AdminController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 120
rs 10
c 2
b 0
f 0
wmc 7
lcom 0
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A create() 0 8 1
A store() 0 17 1
A show() 0 6 1
A edit() 0 10 1
A update() 0 17 1
A destroy() 0 6 1
1
<?php namespace Bantenprov\Admin\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Bantenprov\Admin\Facades\Admin;
6
7
8
/* Models */
9
use Bantenprov\Admin\Models\AdminModel;
10
use Bantenprov\LaravelOpd\Models\LaravelOpdModel;
11
use App\User;
12
13
/* ETC */
14
use Ramsey\Uuid\Uuid;
15
16
/**
17
 * The AdminController class.
18
 *
19
 * @package Bantenprov\Admin
20
 * @author  bantenprov <[email protected]>
21
 */
22
class AdminController extends Controller
23
{
24
    /**
25
     * Display a listing of the resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function index()
30
    {
31
        $admins = AdminModel::with('getUser')->get();
32
33
        return view('admin::index',compact('admins'));
34
    }
35
36
    /**
37
     * Show the form for creating a new resource.
38
     *
39
     * @return \Illuminate\Http\Response
40
     */
41
    public function create()
42
    {
43
        $users = User::doesntHave('admins')->get();
44
45
        $opds = LaravelOpdModel::all();
46
47
        return view('admin::create', compact('users', 'opds'));
48
    }
49
50
    /**
51
     * Store a newly created resource in storage.
52
     *
53
     * @param  \Illuminate\Http\Request  $request
54
     * @return \Illuminate\Http\Response
55
     */
56
    public function store(Request $request)
57
    {
58
        $request->validate([
59
            'opd_id'      => 'required',
60
            'user_id'   => 'required|unique:admins',
61
        ]);
62
63
        AdminModel::create([
64
            'uuid'      => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
65
            'opd_id'      => $request->opd_id,
66
            'user_id'   => $request->user_id,
67
        ]);
68
69
        $request->session()->flash('message', 'Successfully add the admin!');
70
71
        return redirect()->route('admin.index');
72
    }
73
74
    /**
75
     * Display the specified resource.
76
     *
77
     * @param  int  $id
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function show($id)
81
    {
82
        $admin = AdminModel::find($id);
83
84
        return view('admin::show', compact('admin'));
85
    }
86
87
    /**
88
     * Show the form for editing the specified resource.
89
     *
90
     * @param  int  $id
91
     * @return \Illuminate\Http\Response
92
     */
93
    public function edit($id)
94
    {
95
        $admin = AdminModel::find($id);
96
97
        $users = User::doesntHave('admins')->get();
98
99
        $opds = LaravelOpdModel::all();
100
101
        return view('admin::edit', compact('admin','users', 'opds'));
102
    }
103
104
    /**
105
     * Update the specified resource in storage.
106
     *
107
     * @param  \Illuminate\Http\Request  $request
108
     * @param  int  $id
109
     * @return \Illuminate\Http\Response
110
     */
111
    public function update(Request $request, $id)
112
    {
113
114
        $request->validate([
115
            'opd_id'        => 'required',
116
            'user_id'       => 'required|unique:admins',
117
        ]);
118
119
        AdminModel::find($id)->update([
120
            'opd_id'      => $request->opd_id,
121
            'user_id'   => $request->user_id,
122
        ]);
123
124
        $request->session()->flash('message', 'Successfully modified the admin!');
125
126
        return redirect()->route('admin.index');
127
    }
128
129
    /**
130
     * Remove the specified resource from storage.
131
     *
132
     * @param  int  $id
133
     * @return \Illuminate\Http\Response
134
     */
135
    public function destroy($id)
136
    {
137
        AdminModel::find($id)->delete();
138
139
        $request->session()->flash('message', 'Successfully delete the admin!');
0 ignored issues
show
Bug introduced by
The variable $request does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
140
    }
141
}
142