예제 #1
0
 public function test($slug)
 {
     $artikel = \App\posts::where('slug', $slug)->first();
     if (!empty($artikel)) {
         $data = array('data' => $artikel);
         return view('artikel.show')->with($data);
     } else {
         return redirect(url());
     }
 }
예제 #2
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index($slug)
 {
     $data = array('data' => post::where('slug', $slug)->first());
     return view('artikel.show')->with($data);
 }
예제 #3
0
파일: routes.php 프로젝트: heggies/blog
    echo json_encode($arr);
});
Route::get('api/artikel/detail/{slug}', function ($slug) {
    $key = \App\posts::where('slug', $slug)->first();
    $arr[] = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']);
    if (sizeof($key) == 0) {
        $data = array('status' => 'Error', 'error_code' => 404, 'name' => 'Artikel Not Found', 'msg' => 'Artikel Not Found');
        echo json_encode($data);
    } else {
        echo json_encode($arr);
    }
});
Route::get('api/artikel/{type}/{cari}', function ($type, $cari) {
    $avail = array('idpengguna', 'judul', 'slug', 'tag');
    if (in_array($type, $avail)) {
        $data = \App\posts::where($type, $cari)->get();
        $arr = array();
        foreach ($data as $key) {
            $arr = array('slug' => $key['slug'], 'isi' => $key['isi'], 'created_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])['email'], 'tag' => $key['tag'], 'sampul' => url('images/' . $key['sampul']), 'judul' => $key['judul']);
        }
        if (sizeof($data) == 0) {
            $data = array('status' => 'Error', 'error_code' => 404, 'name' => 'artikel_notfound', 'msg' => 'Artikel Not Found');
            echo json_encode($data);
        } else {
            echo json_encode($arr);
        }
    } else {
        $data = array('status' => 'Error', 'error_code' => 304, 'name' => 'type_notfound', 'msg' => 'Type Not Found');
        echo json_encode($data);
    }
});
예제 #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     post::find($id)->delete();
     return redirect(url('artikel'));
 }