Completed
Push — master ( 1c55d7...55a2f4 )
by
unknown
01:30
created

PelayananKesehatanController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Bantenprov\PelayananKesehatan\Http\Controllers;
3
4
use App\Http\Controllers\Controller;
5
use Illuminate\Http\Request;
6
use Bantenprov\PelayananKesehatan\Facades\PelayananKesehatan;
7
use Bantenprov\PelayananKesehatan\Models\PelayananKesehatanModel;
8
9
/**
10
 * The PelayananKesehatanController class.
11
 *
12
 * @package Bantenprov\PelayananKesehatan
13
 * @author  bantenprov <[email protected]>
14
 */
15
class PelayananKesehatanController extends Controller
16
{
17
    public function demo()
18
    {
19
        return PelayananKesehatan::welcome();
20
    }
21
22
    public function index()
23
    {
24
25
        $pelanan_kesehatans = PelayananKesehatanModel::orderBy('kunker','asc')->paginate(10);        
26
27
        /* $nodes = PelayananKesehatanModel::get()->toTree();
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
29
        $traverse = function ($categories, $prefix = '-') use (&$traverse) {
30
            foreach ($categories as $category) {
31
                echo $prefix.' '.$category->kunker.' - '.$category->name.'<br>';
32
33
                $traverse($category->children, $prefix.'-');
34
            }
35
        };
36
37
        $traverse($nodes); */
38
39
40
        return view('pelayanan-kesehatan::index',compact('pelanan_kesehatans'));
41
        
42
    }
43
44
    public function createRoot()
45
    {
46
47
        return view('pelayanan-kesehatan::create-root');
48
    }
49
50
    public function createChild()
51
    {
52
        $unit_kerjas = PelayananKesehatanModel::all();
53
54
        return view('pelayanan-kesehatan::create-child',compact('unit_kerjas'));
55
    }
56
57
    public function addChild($id)
58
    {
59
        $unit_kerja = PelayananKesehatanModel::where('id',$id)->first();
60
61
        return view('pelayanan-kesehatan::add-child',compact('unit_kerja'));
62
    }
63
64
    public function storeRoot(Request $request)
65
    {
66
        $request->validate([
67
            'kunker'            => 'required',
68
            'leveunker'         => 'required',
69
            'name'              => 'required',
70
            'njab'              => 'required',
71
            'npej'              => 'required',
72
        ]);
73
74
        $check_root = PelayananKesehatanModel::where('id',$request->root);
75
76 View Code Duplication
        if($check_root->get()->isEmpty())
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
        {
78
            $unit_kerja = PelayananKesehatanModel::create([
0 ignored issues
show
Unused Code introduced by
$unit_kerja is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
                'kunker' => $request->kunker,
80
                'kunker_sinjab' => '',
81
                'kunker_simral' => '',
82
                'kunker_sinjab' => '',
83
                'name' => $request->name,
84
                'levelunker' => $request->levelunker,
85
                'njab' => $request->njab,
86
                'npej' => $request->npej
87
            ]);
88
        }
89
        else
90
        {
91
            return redirect()->back();
92
        }
93
94
        return redirect()->back();
95
    }
96
97
    public function storeChild(Request $request)
98
    {
99
        $request->validate([
100
            'kunker'            => 'required',
101
            'name'              => 'required',
102
            'njab'              => 'required',
103
            'npej'              => 'required',
104
        ]);
105
106
        $check_root = PelayananKesehatanModel::where('id',$request->root);
107
108
            $check_root->first()->children()->create([
109
                'kunker'            => $request->c_kunker,
110
                'kunker_simral'     => '',
111
                'kunker_sinjab'     => '',
112
                'name'              => $request->c_name,
113
                'levelunker'        => $check_root->first()->levelunker + 1,
114
                'njab'              => $request->c_njab,
115
                'npej'              => $request->c_npej
116
            ]);
117
118
        return redirect()->back();
119
    }
120
121
    public function edit($id)
122
    {
123
        $pelanan_kesehatan = PelayananKesehatanModel::find($id);        
124
125
        return view('pelayanan-kesehatan::edit', compact('pelanan_kesehatan'));
126
    }
127
128
    public function update($id, Request $request)
129
    {        
130
        $request->validate([
131
            'kunker'            => 'required',
132
            'name'              => 'required',
133
            /* 'kunker_sinjab'     => 'required',
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
134
            // 'kunker_simral'     => 'required', */
135
            // 'levelunker'        => 'required',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
136
            'njab'              => 'required',
137
            'npej'              => 'required',
138
        ]);
139
        
140
        PelayananKesehatanModel::find($id)->update([
141
            'kunker'            => $request->kunker ? $request->kunker : '',
142
            'name'              => $request->name  ? $request->name : '',
143
            /* 'kunker_sinjab'     => $request->kunker_sinjab,
144
            'kunker_simral'     => $request->kunker_simral', */
145
            // 'levelunker'        => $request->levelunker  ? $request->levelunker : '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
146
            'njab'              => $request->njab  ? $request->njab : '',
147
            'npej'              => $request->npej  ? $request->npej : '',
148
        ]);
149
150
        $request->session()->flash('message', 'Successfully modified the pelanan_kesehatan!');
151
152
        return redirect()->route('pelanan_kesehatan.index');
153
    }
154
}