@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function index() |
| 17 | 17 | { |
| 18 | - $articles = Articles::orderBy('created_at','desc')->paginate(15); |
|
| 18 | + $articles = Articles::orderBy('created_at', 'desc')->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 | |