@@ -17,22 +17,22 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | $log = new Log; |
| 19 | 19 | |
| 20 | - $log->action = $data['action']; |
|
| 21 | - $log->target = $data['target']; |
|
| 22 | - $log->prefix = $data['prefix']; |
|
| 20 | + $log->action = $data[ 'action' ]; |
|
| 21 | + $log->target = $data[ 'target' ]; |
|
| 22 | + $log->prefix = $data[ 'prefix' ]; |
|
| 23 | 23 | |
| 24 | - switch($data['target']) { |
|
| 25 | - case 'thread' : $log->thread_id = $data['target_id']; break; |
|
| 26 | - case 'article' : $log->article_id = $data['target_id']; break; |
|
| 24 | + switch ($data[ 'target' ]) { |
|
| 25 | + case 'thread' : $log->thread_id = $data[ 'target_id' ]; break; |
|
| 26 | + case 'article' : $log->article_id = $data[ 'target_id' ]; break; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - switch ($data['actor']) { |
|
| 30 | - case 'admin' : $log->admin_id = $data['actor_id']; break; |
|
| 31 | - case 'doctor' : $log->doctor_id = $data['actor_id']; break; |
|
| 32 | - case 'user' : $log->user_id = $data['actor_id']; break; |
|
| 29 | + switch ($data[ 'actor' ]) { |
|
| 30 | + case 'admin' : $log->admin_id = $data[ 'actor_id' ]; break; |
|
| 31 | + case 'doctor' : $log->doctor_id = $data[ 'actor_id' ]; break; |
|
| 32 | + case 'user' : $log->user_id = $data[ 'actor_id' ]; break; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if($log->save()) { |
|
| 35 | + if ($log->save()) { |
|
| 36 | 36 | return true; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | $c = count($logs); |
| 46 | 46 | $r = 0; |
| 47 | 47 | foreach ($logs as $log) { |
| 48 | - if($log->delete()) { |
|
| 48 | + if ($log->delete()) { |
|
| 49 | 49 | $r++; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | - if($c == $r) { |
|
| 52 | + if ($c == $r) { |
|
| 53 | 53 | return true; |
| 54 | 54 | } |
| 55 | 55 | return false; |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | private static function getLogs($data) |
| 59 | 59 | { |
| 60 | 60 | $logs = null; |
| 61 | - if($data['target'] == 'thread') { |
|
| 62 | - $logs = Log::where('thread_id', $data['target_id'])->get(); |
|
| 63 | - } elseif($data['target'] == 'article') { |
|
| 64 | - $logs = Log::where('article_id', $data['target_id'])->get(); |
|
| 61 | + if ($data[ 'target' ] == 'thread') { |
|
| 62 | + $logs = Log::where('thread_id', $data[ 'target_id' ])->get(); |
|
| 63 | + } elseif ($data[ 'target' ] == 'article') { |
|
| 64 | + $logs = Log::where('article_id', $data[ 'target_id' ])->get(); |
|
| 65 | 65 | } |
| 66 | 66 | return $logs; |
| 67 | 67 | } |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | { |
| 13 | 13 | public function __construct() |
| 14 | 14 | { |
| 15 | - $this->middleware('auth', ['except' => [ |
|
| 15 | + $this->middleware('auth', [ 'except' => [ |
|
| 16 | 16 | 'index', 'show' |
| 17 | - ]]); |
|
| 17 | + ] ]); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | $topic = $this->addTopic($request->input('topic')); |
| 64 | 64 | |
| 65 | - if($topic != null) { |
|
| 65 | + if ($topic != null) { |
|
| 66 | 66 | $thread = new Thread; |
| 67 | 67 | $thread->user_id = $this->currentUser()->id; |
| 68 | 68 | $thread->id_topic = $topic->id; |
| 69 | 69 | $thread->question = $request->input('question'); |
| 70 | 70 | |
| 71 | 71 | $log = null; |
| 72 | - if($thread->save()) { |
|
| 72 | + if ($thread->save()) { |
|
| 73 | 73 | $log = Common::registerLog([ |
| 74 | 74 | 'action' => "membuat diskusi baru.", |
| 75 | 75 | 'target' => 'thread', |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | ]); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if($log != null && $log == true) { |
|
| 83 | + if ($log != null && $log == true) { |
|
| 84 | 84 | return redirect(route('user.thread.index'))->with('success', 'Pertanyaan dikirim !'); |
| 85 | 85 | } |
| 86 | 86 | return redirect()->back()->with('failed', 'Gagal mengirim pertanyaan, silahkan coba lagi nanti.'); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | public function show($id) |
| 98 | 98 | { |
| 99 | 99 | $thread = Thread::find($id); |
| 100 | - if(!$thread) { |
|
| 100 | + if (!$thread) { |
|
| 101 | 101 | abort(404); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | $user = $this->currentUser(); |
| 121 | 121 | $thread = Thread::find($id); |
| 122 | - if($thread->user_id != $user->id) { |
|
| 122 | + if ($thread->user_id != $user->id) { |
|
| 123 | 123 | return redirect()->back()->with('warning', 'Anda tidak berhak mengakses laman tersebut.'); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if($thread->doctor_id != null) { |
|
| 126 | + if ($thread->doctor_id != null) { |
|
| 127 | 127 | return redirect()->back()->with('warning', 'Tidak dapat mengubah pertanyaan karena sudah terjawab, silahkan tanyakan pertanyaan baru.'); |
| 128 | 128 | } |
| 129 | 129 | $threads = Thread::orderBy('created_at', 'desc')->paginate(5); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | { |
| 149 | 149 | $user = $this->currentUser(); |
| 150 | 150 | $thread = Thread::find($id); |
| 151 | - if($thread->user_id != $user->id) { |
|
| 151 | + if ($thread->user_id != $user->id) { |
|
| 152 | 152 | return redirect()->back()->with('warning', 'Anda tidak berhak mengubah ulasan tersebut.'); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | $thread->topic = $request->input('topic'); |
| 161 | 161 | $thread->question = $request->input('question'); |
| 162 | - if($thread->save()) { |
|
| 162 | + if ($thread->save()) { |
|
| 163 | 163 | return redirect(route('user.thread.show', $thread->id))->with('success', 'Berhasil mengubah ulasan !'); |
| 164 | 164 | } |
| 165 | 165 | return redirect(route('user.thread.show', $thread->id))->with('success', 'Berhasil mengubah ulasan !'); |
@@ -175,18 +175,18 @@ discard block |
||
| 175 | 175 | { |
| 176 | 176 | $user = $this->currentUser(); |
| 177 | 177 | $thread = Thread::find($id); |
| 178 | - if($thread->user_id != $user->id) { |
|
| 178 | + if ($thread->user_id != $user->id) { |
|
| 179 | 179 | return redirect()->back()->with('warning', 'Anda tidak berhak menghapus ulasan tersebut.'); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $unreg = null; |
| 183 | - if($thread->delete() && $this->deleteTopic($thread->id_topic)) { |
|
| 183 | + if ($thread->delete() && $this->deleteTopic($thread->id_topic)) { |
|
| 184 | 184 | $unreg = Common::unregisterLog([ |
| 185 | 185 | 'target' => 'thread', |
| 186 | 186 | 'target_id' => $id |
| 187 | 187 | ]); |
| 188 | 188 | } |
| 189 | - if($unreg != null && $unreg) { |
|
| 189 | + if ($unreg != null && $unreg) { |
|
| 190 | 190 | return redirect(route('user.profile'))->with('success', 'Ulasan dihapus !'); |
| 191 | 191 | } |
| 192 | 192 | return redirect()->back()->with('failed', 'Gagal menghapus ulasan.'); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | $new = new ThreadTopic; |
| 212 | 212 | $new->topic_name = $topic; |
| 213 | - if($new->save()) { |
|
| 213 | + if ($new->save()) { |
|
| 214 | 214 | return $new; |
| 215 | 215 | } |
| 216 | 216 | return null; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | private function deleteTopic($id) |
| 226 | 226 | { |
| 227 | 227 | $topic = ThreadTopic::find($id); |
| 228 | - if($topic->delete()) { |
|
| 228 | + if ($topic->delete()) { |
|
| 229 | 229 | return true; |
| 230 | 230 | } |
| 231 | 231 | return false; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function index() |
| 17 | 17 | { |
| 18 | - $articles = Articles::orderBy('category','asc')->paginate(15); |
|
| 18 | + $articles = Articles::orderBy('category', 'asc')->paginate(15); |
|
| 19 | 19 | $data = [ |
| 20 | 20 | 'articles' => $articles |
| 21 | 21 | ]; |
@@ -38,20 +38,20 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function store(Request $request) |
| 40 | 40 | { |
| 41 | - $this->validate($request,[ |
|
| 41 | + $this->validate($request, [ |
|
| 42 | 42 | 'category' => 'required', |
| 43 | 43 | 'title' => 'required', |
| 44 | 44 | 'content' => 'required|min:500', |
| 45 | 45 | 'cover_image' => 'image|nullable|max:3999' |
| 46 | 46 | ]); |
| 47 | 47 | |
| 48 | - if($request->hasFile('cover_image')){ |
|
| 48 | + if ($request->hasFile('cover_image')) { |
|
| 49 | 49 | $filenameWithExt = $request->file('cover_image')->getClientOriginalName(); |
| 50 | 50 | $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); |
| 51 | 51 | $extension = $request->file('cover_image')->getClientOriginalExtension(); |
| 52 | 52 | $fileNameToStore = $filename.'_'.time().'.'.$extension; |
| 53 | 53 | $path = $request->file('cover_image')->storeAs('public/cover_images', $fileNameToStore); |
| 54 | - }else { |
|
| 54 | + } else { |
|
| 55 | 55 | $fileNameToStore = 'noimage.jpg'; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $article->category = $request->input('category'); |
| 60 | 60 | $article->title = $request->input('title'); |
| 61 | 61 | $article->content = $request->input('content'); |
| 62 | - if(session('guard') == 'admin') { |
|
| 62 | + if (session('guard') == 'admin') { |
|
| 63 | 63 | $article->admin_id = Auth::guard('admin')->user()->id; |
| 64 | 64 | } else { |
| 65 | 65 | $article->doctor_id = Auth::guard('doctor')->user()->id; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $article->cover_image = $fileNameToStore; |
| 68 | 68 | |
| 69 | 69 | $log = null; |
| 70 | - if($article->save()) { |
|
| 70 | + if ($article->save()) { |
|
| 71 | 71 | $log = Common::registerLog([ |
| 72 | 72 | 'action' => "membuat artikel baru.", |
| 73 | 73 | 'target' => 'article', |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | ]); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if($log != null && $log == true) { |
|
| 82 | - return redirect (route(session('guard').'.article.index'))->with('success', 'Artikel baru berhasil ditambahkan !'); |
|
| 81 | + if ($log != null && $log == true) { |
|
| 82 | + return redirect(route(session('guard').'.article.index'))->with('success', 'Artikel baru berhasil ditambahkan !'); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return redirect(route(session('guard').'.article.create'))->with('failed', 'Gagal menambahkan artikel.'); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | public function show($id) |
| 93 | 93 | { |
| 94 | 94 | $article = Articles::find($id); |
| 95 | - if(!$article) { |
|
| 95 | + if (!$article) { |
|
| 96 | 96 | abort(404); |
| 97 | 97 | } |
| 98 | 98 | return view('pages.ext.view-article')->with('article', $article); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $data = [ |
| 128 | - 'articles' => Articles::where('category', $cat)->orderBy('title','asc')->get(), |
|
| 128 | + 'articles' => Articles::where('category', $cat)->orderBy('title', 'asc')->get(), |
|
| 129 | 129 | 'category' => $category, |
| 130 | 130 | 'cat' => $cat |
| 131 | 131 | ]; |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | $data = [ |
| 158 | 158 | 'articles' => Articles::where('category', $cat) |
| 159 | - ->where('title','LIKE',$name.'%') |
|
| 160 | - ->orderBy('title','asc') |
|
| 159 | + ->where('title', 'LIKE', $name.'%') |
|
| 160 | + ->orderBy('title', 'asc') |
|
| 161 | 161 | ->get(), |
| 162 | 162 | 'category' => $category, |
| 163 | 163 | 'cat' => $cat |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | $cari = $request->cari; |
| 172 | 172 | $articles = Articles::where('category', $cat) |
| 173 | - ->where('content','LIKE','%'.$cari.'%') |
|
| 174 | - ->orderBy('title','asc') |
|
| 173 | + ->where('content', 'LIKE', '%'.$cari.'%') |
|
| 174 | + ->orderBy('title', 'asc') |
|
| 175 | 175 | ->get(); |
| 176 | 176 | $category = null; |
| 177 | 177 | switch ($cat) { |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | public function edit($id) |
| 208 | 208 | { |
| 209 | 209 | $article = Articles::find($id); |
| 210 | - if(!$article) { |
|
| 210 | + if (!$article) { |
|
| 211 | 211 | abort(404); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if($article->writer()['data']->id != Auth::guard(session('guard'))->user()->id) { |
|
| 214 | + if ($article->writer()[ 'data' ]->id != Auth::guard(session('guard'))->user()->id) { |
|
| 215 | 215 | return redirect(session('guard').'/article')->with('warning', 'Anda tidak berhak untuk mengubah Artikel tersebut.'); |
| 216 | 216 | } |
| 217 | 217 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function update(Request $request, $id) |
| 231 | 231 | { |
| 232 | - $this->validate($request,[ |
|
| 232 | + $this->validate($request, [ |
|
| 233 | 233 | 'category' => 'required', |
| 234 | 234 | 'title' => 'required', |
| 235 | 235 | 'content' => 'required|min:500', |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | ]); |
| 239 | 239 | |
| 240 | - if($request->hasFile('cover_image')){ |
|
| 240 | + if ($request->hasFile('cover_image')) { |
|
| 241 | 241 | $filenameWithExt = $request->file('cover_image')->getClientOriginalName(); |
| 242 | 242 | $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); |
| 243 | 243 | $extension = $request->file('cover_image')->getClientOriginalExtension(); |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | $article->category = $request->input('category'); |
| 250 | 250 | $article->title = $request->input('title'); |
| 251 | 251 | $article->content = $request->input('content'); |
| 252 | - if($request->hasFile('cover_image')){ |
|
| 252 | + if ($request->hasFile('cover_image')) { |
|
| 253 | 253 | $article->cover_image = $fileNameToStore; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $log = null; |
| 257 | - if($article->save()) { |
|
| 257 | + if ($article->save()) { |
|
| 258 | 258 | $log = Common::registerLog([ |
| 259 | 259 | 'action' => "membuat perubahan pada artikelnya.", |
| 260 | 260 | 'target' => 'article', |
@@ -265,11 +265,11 @@ discard block |
||
| 265 | 265 | ]); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if($log != null && $log == true) { |
|
| 269 | - return redirect (route(session('guard').'.article.index'))->with('success', 'Artikel berhasil diubah !'); |
|
| 268 | + if ($log != null && $log == true) { |
|
| 269 | + return redirect(route(session('guard').'.article.index'))->with('success', 'Artikel berhasil diubah !'); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - return redirect (route(session('guard').'.article.edit', $id))->with('failed', 'Gagal mengubah artikel !'); |
|
| 272 | + return redirect(route(session('guard').'.article.edit', $id))->with('failed', 'Gagal mengubah artikel !'); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -280,18 +280,18 @@ discard block |
||
| 280 | 280 | { |
| 281 | 281 | $article = Articles::find($id); |
| 282 | 282 | |
| 283 | - if($article->cover_image != 'noimage.jpg'){ |
|
| 283 | + if ($article->cover_image != 'noimage.jpg') { |
|
| 284 | 284 | Storage::delete('public/cover_images/'.$article->cover_image); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | $unreg = null; |
| 288 | - if($article->delete()) { |
|
| 288 | + if ($article->delete()) { |
|
| 289 | 289 | $unreg = Common::unregisterLog([ |
| 290 | 290 | 'target' => 'article', |
| 291 | 291 | 'target_id' => $id |
| 292 | 292 | ]); |
| 293 | 293 | } |
| 294 | - if($unreg != null && $unreg) { |
|
| 294 | + if ($unreg != null && $unreg) { |
|
| 295 | 295 | return redirect()->back()->with('success', 'Artikel dihapus !'); |
| 296 | 296 | } |
| 297 | 297 | |
@@ -11,9 +11,9 @@ discard block |
||
| 11 | 11 | { |
| 12 | 12 | public function __construct() |
| 13 | 13 | { |
| 14 | - $this->middleware('auth:admin', ['except' => [ |
|
| 14 | + $this->middleware('auth:admin', [ 'except' => [ |
|
| 15 | 15 | 'index', 'show' |
| 16 | - ]]); |
|
| 16 | + ] ]); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $threads = null; |
| 28 | 28 | $count = null; |
| 29 | - if($query == "all") { |
|
| 29 | + if ($query == "all") { |
|
| 30 | 30 | $threads = Thread::orderBy('created_at', 'desc')->paginate(15); |
| 31 | - } elseif($query == "answered") { |
|
| 31 | + } elseif ($query == "answered") { |
|
| 32 | 32 | $threads = Thread::where('status', true) |
| 33 | 33 | ->orderBy('created_at', 'desc') |
| 34 | 34 | ->paginate(15); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | public function show($id) |
| 62 | 62 | { |
| 63 | 63 | $thread = Thread::find($id); |
| 64 | - if(!$thread) { |
|
| 64 | + if (!$thread) { |
|
| 65 | 65 | abort(404); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | $thread = Thread::find($id); |
| 86 | 86 | $unreg = null; |
| 87 | - if($thread->delete() && $this->deleteTopic($thread->id_topic)) { |
|
| 87 | + if ($thread->delete() && $this->deleteTopic($thread->id_topic)) { |
|
| 88 | 88 | $unreg = Common::unregisterLog([ |
| 89 | 89 | 'target' => 'thread', |
| 90 | 90 | 'target_id' => $id |
| 91 | 91 | ]); |
| 92 | 92 | } |
| 93 | - if($unreg != null && $unreg) { |
|
| 94 | - return redirect(route('admin.thread.index', ['query' => "all"]))->with('success', 'Diskusi dihapus !'); |
|
| 93 | + if ($unreg != null && $unreg) { |
|
| 94 | + return redirect(route('admin.thread.index', [ 'query' => "all" ]))->with('success', 'Diskusi dihapus !'); |
|
| 95 | 95 | } |
| 96 | 96 | return redirect()->back()->with('failed', 'Gagal menghapus diskusi.'); |
| 97 | 97 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | public function deleteTopic($id) |
| 107 | 107 | { |
| 108 | 108 | $topic = ThreadTopic::find($id); |
| 109 | - if($topic->delete()) { |
|
| 109 | + if ($topic->delete()) { |
|
| 110 | 110 | return true; |
| 111 | 111 | } |
| 112 | 112 | return false; |