/**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     if (Gate::denies('place.update')) {
         return view(config('app.template') . '.error.403');
     }
     $place = Place::find($id);
     if (!$place) {
         return view(config('app.template') . '.error.404');
     }
     $data = ['types' => PlaceKategori::where('active', 1)->lists('nama', 'id'), 'place' => $place];
     return view(config('app.template') . '.place.update', $data);
 }
 public function index(Request $request)
 {
     if (Gate::denies('order.select_place')) {
         return view(config('app.template') . '.error.403');
     }
     $types = PlaceKategori::where('active', 1)->lists('nama', 'id');
     $type = $request->get('type') ? $request->get('type') : PlaceKategori::where('active', 1)->first()->id;
     $tgl = $request->get('tgl') ? $request->get('tgl') : date('Y-m-d');
     if (in_array($type, array_keys($types->toArray()))) {
         $places = Place::leftJoin(DB::raw("( SELECT order_places.`place_id`, orders.`id` AS order_id, orders.`state`\n                FROM order_places INNER JOIN orders ON order_places.`order_id` = orders.`id`\n                WHERE SUBSTRING(orders.tanggal, 1, 10) = '" . $tgl . "' AND orders.`state` = 'On Going' )as order_place_temp"), function ($query) {
             $query->on('places.id', '=', 'order_place_temp.place_id');
         })->where('kategori_id', $type)->where('places.active', 1)->orderBy('places.id')->get();
         $data = ['type' => $type, 'tgl' => Carbon::createFromFormat('Y-m-d', $tgl), 'types' => $types, 'places' => $places];
         return view(config('app.template') . '.order.table', $data);
     } else {
         return view(config('app.template') . '.error.404');
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (Gate::denies('place_kategori.delete')) {
         return view(config('app.template') . '.error.403');
     }
     $kategori = PlaceKategori::find($id);
     if ($kategori && $kategori->update(['active' => 0])) {
         return redirect()->back()->with('succcess', 'Sukses hapus data ' . $kategori->nama . '.');
     }
     return redirect()->back()->withErrors(['failed' => 'Gagal hapus data kategori tempat pelanggan.']);
 }