Completed
Push — master ( 79dc99...137869 )
by
unknown
02:37 queued 10s
created

MasterTarifController::show()   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 namespace Bantenprov\MasterTarif\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Bantenprov\MasterTarif\Facades\MasterTarif;
6
use Bantenprov\MasterTarif\Models\MasterTarifModel;
7
use Bantenprov\DaftarRetribusi\Models\DaftarRetribusiModel;
8
use Ramsey\Uuid\Uuid;
9
10
/**
11
 * Class MasterTarifController
12
 * @package Bantenprov\MasterTarif\Http\Controllers
13
 * @author  bantenprov <[email protected]>
14
 */
15
class MasterTarifController extends Controller
16
{
17
18
    /**
19
     * @return mixed
20
     */
21
    public function index()
22
    {
23
        $master_tarifs = MasterTarifModel::all();
24
25
        return view('master-tarif::index', compact('master_tarifs'));
26
    }
27
28
    /**
29
     * @param Request $request
30
     * @return mixed
31
     */
32
    public function create(Request $request)
33
    {
34
        $daftar_retribusies = DaftarRetribusiModel::all();
35
36
        return view('master-tarif::create', compact('daftar_retribusies'));
37
    }
38
39
    /**
40
     * @param Request $request
41
     */
42
    public function store(Request $request)
43
    {
44
45
        $daftar_retribusi = DaftarRetribusiModel::find($request->daftar_retribusi_id);
46
47
        $request->validate([            
48
            'nama'                  => 'required',
49
            'dasar_hukum'           => 'required',
50
            'status'                => 'required',
51
            'daftar_retribusi_id'   => 'required',
52
        ]);
53
54
        if(is_null($daftar_retribusi)){
55
            return redirect()->back()->withErrors('Error : retribusi yang dipilih tidak ditemukan');
56
        }
57
58 View Code Duplication
        if($request->status > 1 && $request->status < 0){
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...
59
            return redirect()->back()->withErrors('Error : status salah');
60
        }
61
62
        MasterTarifModel::create([
63
            'uuid'                  => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
64
            'nama'                  => $request->nama,
65
            'dasar_hukum'           => $request->dasar_hukum,
66
            'status'                => $request->status,
67
            'daftar_retribusi_id'   => $request->daftar_retribusi_id,
68
            'daftar_retribusi_uuid' => $daftar_retribusi->uuid,
69
            'user_id'               => \Auth::user()->id,
70
            'user_update'           => \Auth::user()->id,
71
        ]);
72
73
        $request->session()->flash('message', 'Successfully add new data');
74
75
        return redirect()->route('master-tarif.index');
76
77
    }
78
79
    /**
80
     * @param $id
81
     * @return mixed
82
     */
83
    public function edit($id)
84
    {
85
        $daftar_retribusies = DaftarRetribusiModel::all();
86
87
        $master_tarif = MasterTarifModel::find($id);
88
89
        return view('master-tarif::edit',compact('daftar_retribusies','master_tarif'));
90
    }
91
92
    /**
93
     * @param Request $request
94
     * @param $id
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $daftar_retribusi = DaftarRetribusiModel::find($request->daftar_retribusi_id);
99
100
        $request->validate([            
101
            'nama'                  => 'required',
102
            'dasar_hukum'           => 'required',
103
            'status'                => 'required',
104
            'daftar_retribusi_id'   => 'required',
105
        ]);
106
107
        if(is_null($daftar_retribusi)){
108
            return redirect()->back()->withErrors('Error : retribusi yang dipilih tidak ditemukan');
109
        }
110
111 View Code Duplication
        if($request->status > 1 && $request->status < 0){
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...
112
            return redirect()->back()->withErrors('Error : status salah');
113
        }
114
115
        MasterTarifModel::find($id)->update([            
116
            'nama'                  => $request->nama,
117
            'dasar_hukum'           => $request->dasar_hukum,
118
            'status'                => $request->status,
119
            'daftar_retribusi_id'   => $request->daftar_retribusi_id,
120
            'daftar_retribusi_uuid' => $daftar_retribusi->uuid,
121
            'user_update'           => \Auth::user()->id,
122
        ]);
123
124
        $request->session()->flash('message', 'Successfully add new data');
125
126
        return redirect()->route('master-tarif.index');
127
    }
128
129
    /**
130
     * @param $id
131
     * @return mixed
132
     */
133
    public function show($id)
134
    {
135
        $master_tarif = MasterTarifModel::find($id);
136
137
        return view('master-tarif::show', compact('master_tarif'));
138
    }
139
140
    /**
141
     * @param $id
142
     */
143
    public function destroy(Request $request, $id)
144
    {
145
        MasterTarifModel::find($id)->delete();
146
147
        $request->session()->flash('message', 'Successfully delete data');
148
149
        return redirect()->route('master-tarif.index');
150
    }
151
152
}
153