method() == 'post') { (new Admin_Location([ 'id_admin' => $driver->id_admin, 'date' => date('Y-m-d H:i:s'), 'lat' => $this->request()['lat'] ? $this->request()['lat'] : $this->request()['latitude'], 'lon' => $this->request()['lon'] ? $this->request()['lon'] : $this->request()['longitude'], 'accuracy' => $this->request()['accuracy'] ]))->save(); } if ( method_exists( $driver, 'location' ) && $driver->location()->id_admin_location) { echo $driver->location()->json(); } else { echo json_encode(null); } break; case 'all': $out = []; $drivers = Admin::drivers(); foreach( $drivers as $driver ){ $out[] = [ 'id_admin' => intval( $driver->id_admin ), 'name' => $driver->name ]; } echo json_encode( $out ); break; case 'list-payment-type': $out = []; $drivers = Admin::drivers(); foreach( $drivers as $driver ){ if( $driver->hasPaymentType() ){ $out[] = [ 'id_admin' => intval( $driver->id_admin ), 'name' => $driver->name ]; } } echo json_encode( $out ); break; default: if ($this->method() == 'post') { // save a setting } echo $driver->json(); break; } } }