Passed
Push — master ( 24e034...f80494 )
by Faiq
08:50
created
app/Http/Controllers/UserController.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
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
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public function index()
34 34
     {
35 35
         $threads = Thread::orderBy('created_at', 'desc')->paginate(5);
36
-        $articles = Articles::where('category','penyakit')->orderBy('created_at','desc')->take(3)->get();
36
+        $articles = Articles::where('category', 'penyakit')->orderBy('created_at', 'desc')->take(3)->get();
37 37
         $data = [
38 38
             'threads' => $threads,
39 39
             'articles' => $articles
@@ -51,11 +51,11 @@  discard block
 block discarded – undo
51 51
     public function profile($query)
52 52
     {
53 53
         $threads = null;
54
-        if($query == "all") {
54
+        if ($query == "all") {
55 55
             $threads = Thread::where('user_id', $this->currentUser()->id)
56 56
                             ->orderBy('updated_at', 'desc')
57 57
                             ->paginate(3);
58
-        } elseif($query == "answered") {
58
+        } elseif ($query == "answered") {
59 59
             $threads = Thread::where('user_id', $this->currentUser()->id)
60 60
                             ->where('status', true)
61 61
                             ->orderBy('updated_at', 'desc')
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
     public function edit($id)
79 79
     {
80 80
         $user = $this->currentUser();
81
-        if($user->id == $id) {
81
+        if ($user->id == $id) {
82 82
             $data = [
83 83
                 'user' => $user
84 84
             ];
85
-            return view ('profile-edit')->with('data', $data);
85
+            return view('profile-edit')->with('data', $data);
86 86
         }
87 87
         return redirect()->back()->with('warning', 'Anda tidak berhak untuk mengakses laman tersebut.');
88 88
     }
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
     public function editPass($id)
96 96
     {
97 97
         $user = $this->currentUser();
98
-        if($user->id == $id) {
98
+        if ($user->id == $id) {
99 99
             $data = [
100 100
                 'user' => $user
101 101
             ];
102
-            return view ('profile-password')->with('data', $data);
102
+            return view('profile-password')->with('data', $data);
103 103
         }
104 104
         return redirect()->back()->with('warning', 'Anda tidak berhak untuk mengakses laman tersebut.');
105 105
     }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function update(Request $request, $id)
115 115
     {
116
-        $this->validate($request,[
116
+        $this->validate($request, [
117 117
             'name' => 'required|min:3',
118 118
             'email' => 'required|email',
119 119
             'image' => 'image|nullable|max:3999'
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
         $img = null;
123 123
         $user = $this->currentUser();
124 124
 
125
-        if($request->hasFile('image')) {
125
+        if ($request->hasFile('image')) {
126 126
 
127
-            if( $user->profile_picture != "user-default.jpg" &&
127
+            if ($user->profile_picture != "user-default.jpg" &&
128 128
                 $user->profile_picture != "user-default-male.png" &&
129 129
                 $user->profile_picture != "user-default-female.png") {
130 130
 
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
         }
152 152
 
153 153
 
154
-        if($this->currentUser()->id == $id) {
154
+        if ($this->currentUser()->id == $id) {
155 155
             $user->name = $request->input('name');
156 156
             $user->biography = $request->input('bio');
157 157
             $user->gender = $request->input('gender');
158 158
             $user->profile_picture = $img;
159 159
             $user->save();
160 160
 
161
-            return redirect (route('user.profile.edit', ['id' => $id]))->with('success', 'Profil berhasil diperbarui !');
161
+            return redirect(route('user.profile.edit', [ 'id' => $id ]))->with('success', 'Profil berhasil diperbarui !');
162 162
         }
163 163
 
164 164
         return redirect()->back()->with('warning', 'Anda tidak berhak untuk mengakses laman tersebut.');
@@ -180,10 +180,10 @@  discard block
 block discarded – undo
180 180
 
181 181
         $user = $this->currentUser();
182 182
 
183
-        if($this->validatePass($request->input('old_password'))) {
183
+        if ($this->validatePass($request->input('old_password'))) {
184 184
             $user->password = Hash::make($request->input('new_password'));
185 185
 
186
-            if($user->save()) {
186
+            if ($user->save()) {
187 187
                 session()->flush();
188 188
 
189 189
                 return redirect(route('login'))->with('success', 'Password berhasil diubah ! Silahkan login kembali.');
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     public function showArticle($id)
202 202
     {
203 203
         $article = Articles::find($id);
204
-        return view('viewarticle')->with('article',$article);
204
+        return view('viewarticle')->with('article', $article);
205 205
     }
206 206
 
207 207
 
@@ -213,23 +213,23 @@  discard block
 block discarded – undo
213 213
         $user = $this->currentUser();
214 214
         $img = null;
215 215
 
216
-        if( $user->profile_picture != "user-default.jpg" &&
216
+        if ($user->profile_picture != "user-default.jpg" &&
217 217
             $user->profile_picture != "user-default-male.png" &&
218 218
             $user->profile_picture != "user-default-female.png") {
219 219
 
220 220
             Storage::delete('public/user_images/'.$user->profile_picture);
221 221
         }
222 222
 
223
-        if( $user->gender != null && $user->gender == "Laki - laki") {
223
+        if ($user->gender != null && $user->gender == "Laki - laki") {
224 224
             $img = "user-default-male.png";
225
-        } elseif($user->gender != null && $user->gender == "Perempuan") {
225
+        } elseif ($user->gender != null && $user->gender == "Perempuan") {
226 226
             $img = "user-default-female.png";
227 227
         } else {
228 228
             $img = "user-default.jpg";
229 229
         }
230 230
 
231 231
         $user->profile_picture = $img;
232
-        if($user->save()) {
232
+        if ($user->save()) {
233 233
             return redirect(route('user.profile.edit', $user->id))->with('success', 'Foto profil dihapus !');
234 234
         }
235 235
     }
@@ -241,14 +241,14 @@  discard block
 block discarded – undo
241 241
     public function destroy()
242 242
     {
243 243
         $user = $this->currentUser();
244
-        if( $user->profile_picture != "user-default.jpg" &&
244
+        if ($user->profile_picture != "user-default.jpg" &&
245 245
             $user->profile_picture != "user-default-male.png" &&
246 246
             $user->profile_picture != "user-default-female.png") {
247 247
 
248 248
             Storage::delete('public/user_images/'.$user->profile_picture);
249 249
         }
250 250
 
251
-        if($user->delete()) {
251
+        if ($user->delete()) {
252 252
             session()->flush();
253 253
             return redirect(route('home'))->with('success', 'Akun berhasil dihapus !');
254 254
         }
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
     private function validatePass(string $oldPassword)
272 272
     {
273 273
         $user = $this->currentUser();
274
-        if(Hash::check($oldPassword, $user->password)) {
274
+        if (Hash::check($oldPassword, $user->password)) {
275 275
             return true;
276 276
         }
277 277
         return false;
Please login to merge, or discard this patch.