1 | <?php |
||
2 | |||
3 | namespace App\Http\Controllers; |
||
4 | |||
5 | use Illuminate\Http\Request; |
||
6 | use App\City; |
||
7 | use App\DoctorSpecialization; |
||
8 | |||
9 | class SpecializationController extends Controller |
||
10 | { |
||
11 | /** |
||
12 | * Display a listing of the resource. |
||
13 | * |
||
14 | * @return \Illuminate\Http\Response |
||
15 | */ |
||
16 | public function index() |
||
17 | { |
||
18 | $specialization = DoctorSpecialization::orderBy('name', 'desc')->paginate(10); |
||
19 | $data = [ |
||
20 | 'specialization' => $specialization |
||
21 | ]; |
||
22 | |||
23 | return view('pages.specialization')->with('data', $data); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Show the form for creating a new resource. |
||
28 | * |
||
29 | * @return \Illuminate\Http\Response |
||
30 | */ |
||
31 | public function create() |
||
32 | { |
||
33 | return view('pages.ext.add-specialization'); |
||
0 ignored issues
–
show
|
|||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Store a newly created resource in storage. |
||
38 | * |
||
39 | * @param \Illuminate\Http\Request $request |
||
40 | * @return \Illuminate\Http\Response |
||
41 | */ |
||
42 | public function store(Request $request) |
||
43 | { |
||
44 | $this->validate($request, [ |
||
45 | 'degree' => 'required', |
||
46 | 'name' => 'required', |
||
47 | 'detail' => 'required|min:300' |
||
48 | ]); |
||
49 | |||
50 | $specialty = new DoctorSpecialization; |
||
51 | $specialty->degree = $request->input('degree'); |
||
52 | $specialty->name = $request->input('name'); |
||
53 | $specialty->detail = $request->input('detail'); |
||
54 | |||
55 | if($specialty->save()) { |
||
56 | return redirect (route('specialty.index'))->with('success', 'Spesialisasi telah di tambahkan'); |
||
0 ignored issues
–
show
|
|||
57 | } |
||
58 | |||
59 | return redirect (route('specialty.index'))->with('failed', 'Gagal menambah spesialisasi !'); |
||
0 ignored issues
–
show
|
|||
60 | |||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Display the specified resource. |
||
65 | * |
||
66 | * @param int $id |
||
67 | * @return \Illuminate\Http\Response |
||
68 | */ |
||
69 | public function show($id) |
||
70 | { |
||
71 | $specialization = DoctorSpecialization::find($id); |
||
72 | return view('pages.ext.view-specialization')->with('specialty', $specialization); |
||
0 ignored issues
–
show
|
|||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Show the form for editing the specified resource. |
||
77 | * |
||
78 | * @param int $id |
||
79 | * @return \Illuminate\Http\Response |
||
80 | */ |
||
81 | public function edit($id) |
||
82 | { |
||
83 | $specialty = DoctorSpecialization::find($id); |
||
84 | return view('pages.ext.edit-specialization')->with('specialty', $specialty); |
||
0 ignored issues
–
show
|
|||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Update the specified resource in storage. |
||
89 | * |
||
90 | * @param \Illuminate\Http\Request $request |
||
91 | * @param int $id |
||
92 | * @return \Illuminate\Http\Response |
||
93 | */ |
||
94 | public function update(Request $request, $id) |
||
95 | { |
||
96 | $this->validate($request, [ |
||
97 | 'degree' => 'required', |
||
98 | 'name' => 'required', |
||
99 | 'detail' => 'required|min:300' |
||
100 | ]); |
||
101 | |||
102 | $specialty = DoctorSpecialization::find($id); |
||
103 | $specialty->degree = $request->input('degree'); |
||
104 | $specialty->name = $request->input('name'); |
||
105 | $specialty->detail = $request->input('detail'); |
||
106 | |||
107 | if($specialty->save()) { |
||
108 | return redirect (route('specialty.index'))->with('success', 'Spesialisasi telah di update'); |
||
0 ignored issues
–
show
|
|||
109 | } |
||
110 | |||
111 | return redirect (route('specialty.edit', $id))->with('failed', 'Gagal memperbaharui spesialisasi !'); |
||
0 ignored issues
–
show
|
|||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Remove the specified resource from storage. |
||
116 | * |
||
117 | * @param int $id |
||
118 | * @return \Illuminate\Http\Response |
||
119 | */ |
||
120 | public function destroy($id) |
||
121 | { |
||
122 | $specialty = DoctorSpecialization::find($id); |
||
123 | if($specialty->delete()) { |
||
124 | return redirect(route('specialty.index')); |
||
0 ignored issues
–
show
|
|||
125 | } |
||
126 | } |
||
127 | |||
128 | public function indexUser() |
||
129 | { |
||
130 | $specialization = DoctorSpecialization::orderBy('name', 'asc')->get(); |
||
131 | $data = [ |
||
132 | 'specialization' => $specialization |
||
133 | ]; |
||
134 | |||
135 | return view('LSdoctor')->with('data', $data); |
||
136 | } |
||
137 | |||
138 | public function indexSearch() |
||
139 | { |
||
140 | $specialization = DoctorSpecialization::orderBy('created_at','desc')->orderBy('name', 'asc')->take(6)->get(); |
||
141 | $location = City::orderBy('name','asc')->pluck('name','id'); |
||
142 | $data = [ |
||
143 | 'specialization' => $specialization, |
||
144 | 'location' => $location |
||
145 | ]; |
||
146 | |||
147 | return view('SearchDokter')->with('data', $data); |
||
148 | } |
||
149 | |||
150 | public function searchSpecialty(Request $request) |
||
151 | { |
||
152 | $specialization = DoctorSpecialization::where('name','LIKE','%'.$request->specialty.'%')->orderBy('name','asc')->get(); |
||
153 | $data = [ |
||
154 | 'specialization' => $specialization |
||
155 | ]; |
||
156 | |||
157 | return view('LSdoctor')->with('data',$data); |
||
158 | } |
||
159 | } |
||
160 |