orderBy('name')->get(); else $datas = \App\Models\Nation::orderBy('name')->get(); $data = array(); foreach($datas as $d) { $data[] = array("id" => $d->id, "text" => $d->name); } return array("results" => $data); }); Route::get('/provinces/{nation_id}', function($nation_id){ if (isset($_GET["q"])) $datas = \App\Models\Province::where('nation_id', $nation_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get(); else $datas = \App\Models\Province::where('nation_id', $nation_id)->orderBy('name')->get(); $data = array(); foreach($datas as $d) { $data[] = array("id" => $d->id, "text" => $d->name); } return array("results" => $data); }); Route::get('/cities/{province_id}', function($province_id){ if (isset($_GET["q"])) $datas = \App\Models\City::where('province_id', $province_id)->where('name', 'like', $_GET["q"] . '%')->orderBy('name')->get(); else $datas = \App\Models\City::where('province_id', $province_id)->orderBy('name')->get(); $data = array(); foreach($datas as $d) { $data[] = array("id" => $d->id, "text" => $d->name); } return array("results" => $data); }); Route::get('/get_members', function(){ $datas = []; // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0); $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone')->where('id', '>', 0); if ($_GET["cards"] != "") { $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id'); $x = $x->whereIn('id', $card_ids); } if ($_GET["categories"] != "") { $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["categories"]))->pluck('member_id'); $x = $x->whereIn('id', $cats_ids); } $certs = []; if ($_GET["chkCertificateNormal"] != "") { $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id'); $x = $x->whereIn('id', $normal);; } if ($_GET["chkCertificateAgonistico"] != "") { $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id'); $x = $x->whereIn('id', $agonistic); } if ($_GET["chkCertificateScaduti"] != "") { $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id'); $x = $x->whereIn('id', $scaduto); } if ($_GET["chkCertificateScadenza"] != "") { $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id'); $x = $x->whereIn('id', $scadenza); } if (sizeof($certs) > 0) { $x = $x->whereIn('id', $certs); } $x = $x->get(); foreach($x as $idx => $r) { $status = $r->getStatus(); $status = $status["status"]; $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due'; $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'; $state = $r->isActive(); $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : ''; $x .= "|"; $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : ''; $x .= "|"; $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : ''); $x .= "|"; $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : ''; $has_certificate = $r->hasCertificate(); $y = ''; if($has_certificate["date"] != '') { if($has_certificate["date"] < date("Y-m-d")) $y .= '0'; if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month"))) $y .= '1'; if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month"))) $y .= '2'; $y .= '|'; $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : ''; } $datas[] = array( 'id' => $r->id, 'first_name' => $r->first_name, 'last_name' => $r->last_name, 'phone' => $r->phone, 'age' => $r->getAge(), 'status' => $class . "|" . $text, 'state' => $x, 'certificate' => $y, 'action' => $r->id ); /* $r->age = $r->getAge(); $active = $r->isActive(); $r->status = $active["status"]; $r->date = $active["date"] . "|" . $r->hasCertificate()["date"]; $r->state = $r->getStatus()["status"]; $r->action = '';*/ } /* if ($this->sortAsc) $this->records = $this->records->sortBy($this->sortField); else $this->records = $this->records->sortByDesc($this->sortField); */ // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10); return json_encode(array("data" => $datas)); });