Пример #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $data = array('data' => post::all());
     return view('artikel.all')->with($data);
 }
Пример #2
0
    $data = array('artikel' => array('id' => 1, 'judul' => 'judul artikel', 'isi' => 'isi artikel', 'timestamps' => '2015-01-01 01:01:01'));
    $json = json_encode($data);
    echo $json;
    //	obj = json_decode($json);
    //	echo "<pre>".print
});
Route::get('api/artikel/all', function () {
    /*		$key = url("api/artikel/all");
    		$ch =curl_init($key);
    		curl_setopt($ch, CURLOPT_URL, $key);
    		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $key);
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER, $key);
    		$hasil = curl_exec($ch);
    		curl_close($ch);
    */
    $data = \App\post::all();
    $arr = array();
    foreach ($data as $key) {
        $arr[] = array('slug' => $key['slug'], 'isi' => $key['isi'], 'create_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])->first()['email'], 'tag' => $key['tag'], 'sampul' => url('images/', $key['sampul']), 'judul' => $key['judul']);
    }
    echo json_encode($arr);
});
Route::get("api/artikel/detail/{slug}", function ($slug) {
    $data = \App\post::where('slug', $slug)->first();
    $arr = array('slug' => $key['slug'], 'isi' => $key['isi'], 'create_at' => $key['created_at'], 'author' => \App\User::find($key['idpengguna'])->first()['email'], 'tag' => $key['tag'], 'sampul' => url('images/', $key['sampul']), 'judul' => $key['judul']);
    if (sizeof($key) == 0) {
        $data = array('status' => "Erorr", 'error_code' => 404, 'name' => 'artikel_notfound', 'msg' => 'Artikel Not Found');
        echo json_encode($data);
    } else {
        echo json_encode($arr);
    }