public function getPlace(Request $request) { if ($request->get('id')) { return Place::with('kategori')->where('active', 1)->where('id', $request->get('id'))->first(); } elseif ($request->get('ids')) { return Place::with('kategori')->where('active', 1)->whereIn('id', explode('+', $request->get('ids')))->get(); } else { $tgl = $request->get('date') ? $request->get('date') : date('Y-m-d'); $tgl = $tgl != "" ? $tgl : date('Y-m-d'); $ready = $request->get('ready') ? $request->get('ready') : 'Ya'; $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'); }); if ($ready == 'Ya') { $places = $places->whereNull('order_place_temp.order_id'); } else { $places = $places->whereNotNull('order_place_temp.order_id'); } $places = $places->where('nama', 'like', '%' . $request->get('q') . '%')->where('active', 1)->with('kategori')->get(); return $places; } }