1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Doctor; |
6
|
|
|
use App\DoctorSpecialization; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Support\Facades\Hash; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class DoctorController extends Controller |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Display a listing of the resource. |
15
|
|
|
* |
16
|
|
|
* @return \Illuminate\Http\Response |
17
|
|
|
*/ |
18
|
|
|
public function index() |
19
|
|
|
{ |
20
|
|
|
$doctor = Doctor::orderBy('name','asc')->paginate(10); |
21
|
|
|
$data = [ |
22
|
|
|
'role' => session('role'), |
23
|
|
|
'doctor' => $doctor, |
24
|
|
|
]; |
25
|
|
|
return view('pages.doctor')->with('data',$data); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Show the form for creating a new resource. |
30
|
|
|
* |
31
|
|
|
* @return \Illuminate\Http\Response |
32
|
|
|
*/ |
33
|
|
|
public function create() |
34
|
|
|
{ |
35
|
|
|
$specialization = DoctorSpecialization::pluck('name', 'id'); |
36
|
|
|
return view('pages.ext.add-doctor')->with('specialization', $specialization); |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Store a newly created resource in storage. |
41
|
|
|
* |
42
|
|
|
* @param Request $request |
43
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
44
|
|
|
* @throws \Illuminate\Validation\ValidationException |
45
|
|
|
*/ |
46
|
|
|
public function store(Request $request) |
47
|
|
|
{ |
48
|
|
|
$this->validate($request,[ |
49
|
|
|
'specialty' => 'required', |
50
|
|
|
'name' => 'required|min:3|max:50', |
51
|
|
|
'license' => 'required|min:3|max:191', |
52
|
|
|
'email' => 'required', |
53
|
|
|
'password' => 'required_with:password_confirmation|same:password_confirmation|min:6', |
54
|
|
|
'password_confirmation' => 'min:6' |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
$doctor = new Doctor; |
59
|
|
|
$doctor->name = $request->input('name'); |
60
|
|
|
$doctor->specialization_id = $request->input('specialty'); |
61
|
|
|
$doctor->license = $request->input('license'); |
62
|
|
|
$doctor->email = $request->input('email'); |
63
|
|
|
$doctor->password = Hash::make($request->password); |
64
|
|
|
|
65
|
|
|
if($doctor->save()) { |
66
|
|
|
return redirect (route('doctor.index'))->with('success', 'Berhasil Menambahkan Dokter !'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return redirect (route('doctor.index'))->with('failed', 'Gagal menambah dokter !'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Display the specified resource. |
74
|
|
|
* |
75
|
|
|
* @param int $id |
76
|
|
|
* @return \Illuminate\Http\Response |
77
|
|
|
*/ |
78
|
|
|
public function show($id) |
79
|
|
|
{ |
80
|
|
|
$doctor = Doctor::where('specialization_id',$id)->orderBy('name','asc')->paginate(5); |
81
|
|
|
$data = [ |
82
|
|
|
'doctor' => $doctor |
83
|
|
|
]; |
84
|
|
|
return view('listDoctor')->with('data',$data); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function showDoctor($id) |
88
|
|
|
{ |
89
|
|
|
$doctor = Doctor::find($id); |
90
|
|
|
|
91
|
|
|
return view('viewDoctor')->with('doctor',$doctor); |
92
|
|
|
} |
93
|
|
|
/** |
94
|
|
|
* Show the form for editing the specified resource. |
95
|
|
|
* |
96
|
|
|
* @param int $id |
97
|
|
|
* @return \Illuminate\Http\Response |
98
|
|
|
*/ |
99
|
|
|
public function edit($id) |
100
|
|
|
{ |
101
|
|
|
$doctor = Doctor::find($id); |
102
|
|
|
$data = [ |
103
|
|
|
'role' => session('role'), |
104
|
|
|
'doctor' => $doctor |
105
|
|
|
]; |
106
|
|
|
return view('pages.ext.edit-dokter')->with('data', $data); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Update the specified resource in storage. |
111
|
|
|
* |
112
|
|
|
* @param Request $request |
113
|
|
|
* @param $id |
114
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
115
|
|
|
* @throws \Illuminate\Validation\ValidationException |
116
|
|
|
*/ |
117
|
|
|
public function update(Request $request, $id) |
118
|
|
|
{ |
119
|
|
|
$this->validate($request,[ |
120
|
|
|
'name' => 'required|min:3|max:50', |
121
|
|
|
'password' => 'required_with:password_confirmation|same:password_confirmation|min:6', |
122
|
|
|
'password_confirmation' => 'min:6' |
123
|
|
|
]); |
124
|
|
|
|
125
|
|
|
$pass = Hash::make($request->password); |
126
|
|
|
$doctor = Doctor::find($id); |
127
|
|
|
$doctor->name = $request->input('name'); |
128
|
|
|
$doctor->password = $pass; |
129
|
|
|
if($doctor->save()) { |
130
|
|
|
return redirect (route('doctor.index'))->with('success', 'Doktor berhasil di update !'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return redirect (route('doctor.edit', $id))->with('failed', 'Gagal memperbaharui dokter !'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
// public function showSpecialty() |
137
|
|
|
// { |
138
|
|
|
|
139
|
|
|
// } |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Remove the specified resource from storage. |
143
|
|
|
* |
144
|
|
|
* @param int $id |
145
|
|
|
* @return \Illuminate\Http\Response |
146
|
|
|
*/ |
147
|
|
|
public function destroy($id) |
148
|
|
|
{ |
149
|
|
|
$doctor = Doctor::find($id); |
150
|
|
|
$doctor->delete(); |
151
|
|
|
|
152
|
|
|
return redirect (route('doctor.index')); |
|
|
|
|
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|