1
|
|
|
<?php namespace Bantenprov\YankesInfoKamar\Http\Controllers; |
2
|
|
|
|
3
|
|
|
use App\Http\Controllers\Controller; |
4
|
|
|
use Illuminate\Http\Request; |
5
|
|
|
use Bantenprov\YankesInfoKamar\Facades\InfoKamar; |
6
|
|
|
use Bantenprov\YankesInfoKamar\Models\Ruangrawat; |
7
|
|
|
use Bantenprov\YankesInfoKamar\Models\Kelasrawat; |
8
|
|
|
use Bantenprov\YankesInfoKamar\Requests\StoreRuang; |
9
|
|
|
use Bantenprov\YankesInfoKamar\Requests\UpdateRuang; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* The InfoKamarController class. |
13
|
|
|
* |
14
|
|
|
* @package Supriyanih\InfoKamar |
15
|
|
|
* @author supriyanih <[email protected]> |
16
|
|
|
*/ |
17
|
|
View Code Duplication |
class RuangController extends Controller |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
public function index(){ |
21
|
|
|
|
22
|
|
|
$ruang = Ruangrawat::with('kelas')->paginate(5); |
23
|
|
|
return view('info-kamar::ruang.index', compact('ruang')); |
24
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function create() |
28
|
|
|
{ |
29
|
|
|
$kelas = Kelasrawat::all(); |
30
|
|
|
return view('info-kamar::ruang.create', compact('kelas')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function store(StoreRuang $req) |
34
|
|
|
{ |
35
|
|
|
$this->validate($req,[ |
36
|
|
|
'kelas_id' => 'required', |
37
|
|
|
'kode_ruang' =>'required', |
38
|
|
|
'nama_ruang' => 'required' |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$ruang = new Ruangrawat; |
42
|
|
|
$ruang->kelas_id = $req->kelas_id; |
43
|
|
|
$ruang->kode_ruang = $req->kode_ruang; |
44
|
|
|
$ruang->nama_ruang = $req->nama_ruang; |
45
|
|
|
$ruang->save(); |
46
|
|
|
|
47
|
|
|
\Session::flash('flash_message', 'Ruang Rawat Inap Berhasil Di buat'); |
48
|
|
|
return redirect()->route('ruang.index'); |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function show($id) |
53
|
|
|
{ |
54
|
|
|
$ruang = Ruangrawat::with('kelas')->findOrFail($id); |
55
|
|
|
return view('info-kamar::ruang.show', compact('ruang')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function edit($id) |
59
|
|
|
{ |
60
|
|
|
$kelas = Kelasrawat::all(); |
61
|
|
|
$ruang = Ruangrawat::findOrFail($id); |
62
|
|
|
|
63
|
|
|
return view('info-kamar::ruang.edit', compact('ruang','kelas')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function update(UpdateRuang $request, $id) |
67
|
|
|
{ |
68
|
|
|
$this->validate($request,[ |
69
|
|
|
'kelas_id' => 'required', |
70
|
|
|
'kode_ruang' => 'required', |
71
|
|
|
'nama_ruang' => 'required', |
72
|
|
|
]); |
73
|
|
|
$ruang = Ruangrawat::findOrFail($id); |
74
|
|
|
$ruang->kelas_id = $request->kelas_id; |
75
|
|
|
$ruang->kode_ruang = $request->kode_ruang; |
76
|
|
|
$ruang->nama_ruang = $request->nama_ruang; |
77
|
|
|
$ruang->save(); |
78
|
|
|
\Session::flash('flash_message', 'ruang Rawat Inap Berhasil di UPDATE'); |
79
|
|
|
return redirect()->route('ruang.index'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function destroy($id) |
83
|
|
|
{ |
84
|
|
|
|
85
|
|
|
Ruangrawat::find($id)->delete(); |
86
|
|
|
return redirect()->route('ruang.index'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
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.