@@ -8,8 +8,7 @@ discard block |
||
8 | 8 | use Illuminate\Foundation\Auth\User as Authenticatable; |
9 | 9 | use Illuminate\Support\Facades\Auth; |
10 | 10 | |
11 | -class User extends Authenticatable |
|
12 | -{ |
|
11 | +class User extends Authenticatable { |
|
13 | 12 | use Notifiable; |
14 | 13 | |
15 | 14 | /** |
@@ -47,14 +46,16 @@ discard block |
||
47 | 46 | 'updated_at' |
48 | 47 | ]; |
49 | 48 | |
50 | - public function thread() { |
|
49 | + public function thread() |
|
50 | + { |
|
51 | 51 | return $this->hasMany('App\Thread', 'user_id'); |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return int |
56 | 56 | */ |
57 | - public function threadAnswered() { |
|
57 | + public function threadAnswered() |
|
58 | + { |
|
58 | 59 | return count( |
59 | 60 | Thread::where('status', true) |
60 | 61 | ->where('user_id', Auth::guard('web') |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use Illuminate\Database\Eloquent\Model; |
6 | 6 | |
7 | -class Thread extends Model |
|
8 | -{ |
|
7 | +class Thread extends Model { |
|
9 | 8 | protected $table = 'threads'; |
10 | 9 | |
11 | 10 | protected $dates = [ |
@@ -13,19 +12,23 @@ discard block |
||
13 | 12 | 'updated_at' |
14 | 13 | ]; |
15 | 14 | |
16 | - public function topic() { |
|
15 | + public function topic() |
|
16 | + { |
|
17 | 17 | return $this->belongsTo('App\ThreadTopic', 'id_topic'); |
18 | 18 | } |
19 | 19 | |
20 | - public function user() { |
|
20 | + public function user() |
|
21 | + { |
|
21 | 22 | return $this->belongsTo('App\User'); |
22 | 23 | } |
23 | 24 | |
24 | - public function doctor() { |
|
25 | + public function doctor() |
|
26 | + { |
|
25 | 27 | return $this->belongsTo('App\Doctor'); |
26 | 28 | } |
27 | 29 | |
28 | - public function trimStr(string $string) { |
|
30 | + public function trimStr(string $string) |
|
31 | + { |
|
29 | 32 | if(strlen($string) > 200) { |
30 | 33 | return substr($string, 0, 200).'...'; |
31 | 34 | } |
@@ -20,10 +20,10 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function __construct() |
22 | 22 | { |
23 | - $this->middleware('auth', ['except' => [ |
|
23 | + $this->middleware('auth', [ 'except' => [ |
|
24 | 24 | 'index', |
25 | 25 | 'showArticle' |
26 | - ]]); |
|
26 | + ] ]); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function index() |
34 | 34 | { |
35 | - $article = Articles::where('category','penyakit')->orderBy('created_at','desc')->take(3)->get(); |
|
35 | + $article = Articles::where('category', 'penyakit')->orderBy('created_at', 'desc')->take(3)->get(); |
|
36 | 36 | return view('home')->with('article', $article); |
37 | 37 | } |
38 | 38 | |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | public function profile($query) |
47 | 47 | { |
48 | 48 | $threads = null; |
49 | - if($query == "all") { |
|
49 | + if ($query == "all") { |
|
50 | 50 | $threads = Thread::where('user_id', $this->currentUser()->id) |
51 | 51 | ->orderBy('created_at', 'desc') |
52 | 52 | ->paginate(3); |
53 | - } elseif($query == "answered") { |
|
53 | + } elseif ($query == "answered") { |
|
54 | 54 | $threads = Thread::where('user_id', $this->currentUser()->id) |
55 | 55 | ->where('status', true) |
56 | 56 | ->orderBy('created_at', 'desc') |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | public function edit($id) |
74 | 74 | { |
75 | 75 | $user = $this->currentUser(); |
76 | - if($user->id == $id) { |
|
76 | + if ($user->id == $id) { |
|
77 | 77 | $data = [ |
78 | 78 | 'user' => $user |
79 | 79 | ]; |
80 | - return view ('profile-edit')->with('data', $data); |
|
80 | + return view('profile-edit')->with('data', $data); |
|
81 | 81 | } |
82 | 82 | return redirect()->back()->with('warning', 'Anda tidak berhak untuk mengakses laman tersebut.'); |
83 | 83 | } |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | public function editPass($id) |
91 | 91 | { |
92 | 92 | $user = $this->currentUser(); |
93 | - if($user->id == $id) { |
|
93 | + if ($user->id == $id) { |
|
94 | 94 | $data = [ |
95 | 95 | 'user' => $user |
96 | 96 | ]; |
97 | - return view ('profile-password')->with('data', $data); |
|
97 | + return view('profile-password')->with('data', $data); |
|
98 | 98 | } |
99 | 99 | return redirect()->back()->with('warning', 'Anda tidak berhak untuk mengakses laman tersebut.'); |
100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function update(Request $request, $id) |
110 | 110 | { |
111 | - $this->validate($request,[ |
|
111 | + $this->validate($request, [ |
|
112 | 112 | 'name' => 'required|min:3', |
113 | 113 | 'email' => 'required|email', |
114 | 114 | 'image' => 'image|nullable|max:3999' |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | $img = null; |
118 | 118 | $user = $this->currentUser(); |
119 | 119 | |
120 | - if($request->hasFile('image')) { |
|
120 | + if ($request->hasFile('image')) { |
|
121 | 121 | |
122 | - if( $user->profile_picture != "user-default.jpg" && |
|
122 | + if ($user->profile_picture != "user-default.jpg" && |
|
123 | 123 | $user->profile_picture != "user-default-male.png" && |
124 | 124 | $user->profile_picture != "user-default-female.png") { |
125 | 125 | |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | |
149 | - if($this->currentUser()->id == $id) { |
|
149 | + if ($this->currentUser()->id == $id) { |
|
150 | 150 | $user->name = $request->input('name'); |
151 | 151 | $user->biography = $request->input('bio'); |
152 | 152 | $user->gender = $request->input('gender'); |
153 | 153 | $user->profile_picture = $img; |
154 | 154 | $user->save(); |
155 | 155 | |
156 | - return redirect (route('user.profile.edit', ['id' => $id]))->with('success', 'Profil berhasil diperbarui !'); |
|
156 | + return redirect(route('user.profile.edit', [ 'id' => $id ]))->with('success', 'Profil berhasil diperbarui !'); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return redirect()->back()->with('warning', 'Anda tidak berhak untuk mengakses laman tersebut.'); |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | |
176 | 176 | $user = $this->currentUser(); |
177 | 177 | |
178 | - if($this->validatePass($request->input('old_password'))) { |
|
178 | + if ($this->validatePass($request->input('old_password'))) { |
|
179 | 179 | $user->password = Hash::make($request->input('new_password')); |
180 | 180 | |
181 | - if($user->save()) { |
|
181 | + if ($user->save()) { |
|
182 | 182 | session()->flush(); |
183 | 183 | |
184 | 184 | return redirect(route('login'))->with('success', 'Password berhasil diubah ! Silahkan login kembali.'); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | public function showArticle($id) |
197 | 197 | { |
198 | 198 | $article = Articles::find($id); |
199 | - return view('viewarticle')->with('article',$article); |
|
199 | + return view('viewarticle')->with('article', $article); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -208,23 +208,23 @@ discard block |
||
208 | 208 | $user = $this->currentUser(); |
209 | 209 | $img = null; |
210 | 210 | |
211 | - if( $user->profile_picture != "user-default.jpg" && |
|
211 | + if ($user->profile_picture != "user-default.jpg" && |
|
212 | 212 | $user->profile_picture != "user-default-male.png" && |
213 | 213 | $user->profile_picture != "user-default-female.png") { |
214 | 214 | |
215 | 215 | Storage::delete('public/user_images/'.$user->profile_picture); |
216 | 216 | } |
217 | 217 | |
218 | - if( $user->gender != null && $user->gender == "Laki - laki") { |
|
218 | + if ($user->gender != null && $user->gender == "Laki - laki") { |
|
219 | 219 | $img = "user-default-male.png"; |
220 | - } elseif($user->gender != null && $user->gender == "Perempuan") { |
|
220 | + } elseif ($user->gender != null && $user->gender == "Perempuan") { |
|
221 | 221 | $img = "user-default-female.png"; |
222 | 222 | } else { |
223 | 223 | $img = "user-default.jpg"; |
224 | 224 | } |
225 | 225 | |
226 | 226 | $user->profile_picture = $img; |
227 | - if($user->save()) { |
|
227 | + if ($user->save()) { |
|
228 | 228 | return redirect(route('user.profile.edit', $user->id))->with('success', 'Foto profil dihapus !'); |
229 | 229 | } |
230 | 230 | } |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | public function destroy() |
237 | 237 | { |
238 | 238 | $user = $this->currentUser(); |
239 | - if( $user->profile_picture != "user-default.jpg" && |
|
239 | + if ($user->profile_picture != "user-default.jpg" && |
|
240 | 240 | $user->profile_picture != "user-default-male.png" && |
241 | 241 | $user->profile_picture != "user-default-female.png") { |
242 | 242 | |
243 | 243 | Storage::delete('public/user_images/'.$user->profile_picture); |
244 | 244 | } |
245 | 245 | |
246 | - if($user->delete()) { |
|
246 | + if ($user->delete()) { |
|
247 | 247 | session()->flush(); |
248 | 248 | return redirect(route('home'))->with('success', 'Akun berhasil dihapus !'); |
249 | 249 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | private function validatePass(string $oldPassword) |
267 | 267 | { |
268 | 268 | $user = $this->currentUser(); |
269 | - if(Hash::check($oldPassword, $user->password)) { |
|
269 | + if (Hash::check($oldPassword, $user->password)) { |
|
270 | 270 | return true; |
271 | 271 | } |
272 | 272 | return false; |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | { |
12 | 12 | public function __construct() |
13 | 13 | { |
14 | - $this->middleware('auth', ['except' => [ |
|
14 | + $this->middleware('auth', [ 'except' => [ |
|
15 | 15 | 'index', 'show' |
16 | - ]]); |
|
16 | + ] ]); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | |
62 | 62 | $topic = $this->addTopic($request->input('topic')); |
63 | 63 | |
64 | - if($topic != null) { |
|
64 | + if ($topic != null) { |
|
65 | 65 | $thread = new Thread; |
66 | 66 | $thread->user_id = $this->currentUser()->id; |
67 | 67 | $thread->id_topic = $topic->id; |
68 | 68 | $thread->question = $request->input('question'); |
69 | 69 | |
70 | - if($thread->save()) { |
|
70 | + if ($thread->save()) { |
|
71 | 71 | return redirect(route('user.thread.index'))->with('success', 'Pertanyaan dikirim !'); |
72 | 72 | } |
73 | 73 | return redirect()->back()->with('failed', 'Gagal mengirim pertanyaan, silahkan coba lagi nanti.'); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | public function show($id) |
85 | 85 | { |
86 | 86 | $thread = Thread::find($id); |
87 | - if(!$thread) { |
|
87 | + if (!$thread) { |
|
88 | 88 | abort(404); |
89 | 89 | } |
90 | 90 | |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | { |
107 | 107 | $user = $this->currentUser(); |
108 | 108 | $thread = Thread::find($id); |
109 | - if($thread->user_id != $user->id) { |
|
109 | + if ($thread->user_id != $user->id) { |
|
110 | 110 | return redirect()->back()->with('warning', 'Anda tidak berhak mengakses laman tersebut.'); |
111 | 111 | } |
112 | 112 | |
113 | - if($thread->doctor_id != null) { |
|
113 | + if ($thread->doctor_id != null) { |
|
114 | 114 | return redirect()->back()->with('warning', 'Tidak dapat mengubah pertanyaan karena sudah terjawab, silahkan tanyakan pertanyaan baru.'); |
115 | 115 | } |
116 | 116 | $threads = Thread::orderBy('created_at', 'desc')->paginate(5); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | { |
136 | 136 | $user = $this->currentUser(); |
137 | 137 | $thread = Thread::find($id); |
138 | - if($thread->user_id != $user->id) { |
|
138 | + if ($thread->user_id != $user->id) { |
|
139 | 139 | return redirect()->back()->with('warning', 'Anda tidak berhak mengubah ulasan tersebut.'); |
140 | 140 | } |
141 | 141 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | $thread->topic = $request->input('topic'); |
148 | 148 | $thread->question = $request->input('question'); |
149 | - if($thread->save()) { |
|
149 | + if ($thread->save()) { |
|
150 | 150 | return redirect(route('user.thread.show', $thread->id))->with('success', 'Berhasil mengubah ulasan !'); |
151 | 151 | } |
152 | 152 | return redirect(route('user.thread.show', $thread->id))->with('success', 'Berhasil mengubah ulasan !'); |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | { |
163 | 163 | $user = $this->currentUser(); |
164 | 164 | $thread = Thread::find($id); |
165 | - if($thread->user_id != $user->id) { |
|
165 | + if ($thread->user_id != $user->id) { |
|
166 | 166 | return redirect()->back()->with('warning', 'Anda tidak berhak menghapus ulasan tersebut.'); |
167 | 167 | } |
168 | 168 | |
169 | - if($thread->delete() && $this->deleteTopic($thread->id_topic)) { |
|
169 | + if ($thread->delete() && $this->deleteTopic($thread->id_topic)) { |
|
170 | 170 | return redirect(route('user.profile'))->with('success', 'Ulasan dihapus !'); |
171 | 171 | } |
172 | 172 | return redirect()->back()->with('failed', 'Gagal menghapus ulasan.'); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | private function addTopic(string $topic) { |
185 | 185 | $new = new ThreadTopic; |
186 | 186 | $new->topic_name = $topic; |
187 | - if($new->save()) { |
|
187 | + if ($new->save()) { |
|
188 | 188 | return $new; |
189 | 189 | } |
190 | 190 | return null; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | private function deleteTopic($id) { |
200 | 200 | $topic = ThreadTopic::find($id); |
201 | - if($topic->delete()) { |
|
201 | + if ($topic->delete()) { |
|
202 | 202 | return true; |
203 | 203 | } |
204 | 204 | return false; |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | use App\Thread; |
8 | 8 | use App\ThreadTopic; |
9 | 9 | |
10 | -class ThreadAskController extends Controller |
|
11 | -{ |
|
10 | +class ThreadAskController extends Controller { |
|
12 | 11 | public function __construct() |
13 | 12 | { |
14 | 13 | $this->middleware('auth', ['except' => [ |
@@ -173,7 +172,8 @@ discard block |
||
173 | 172 | } |
174 | 173 | |
175 | 174 | |
176 | - private function currentUser() { |
|
175 | + private function currentUser() |
|
176 | + { |
|
177 | 177 | return Auth::guard('web')->user(); |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,8 @@ discard block |
||
181 | 181 | * @param string $topic |
182 | 182 | * @return ThreadTopic|null |
183 | 183 | */ |
184 | - private function addTopic(string $topic) { |
|
184 | + private function addTopic(string $topic) |
|
185 | + { |
|
185 | 186 | $new = new ThreadTopic; |
186 | 187 | $new->topic_name = $topic; |
187 | 188 | if($new->save()) { |
@@ -196,7 +197,8 @@ discard block |
||
196 | 197 | * @param int $id |
197 | 198 | * @return bool |
198 | 199 | */ |
199 | - private function deleteTopic($id) { |
|
200 | + private function deleteTopic($id) |
|
201 | + { |
|
200 | 202 | $topic = ThreadTopic::find($id); |
201 | 203 | if($topic->delete()) { |
202 | 204 | return true; |