public function postTestAuthorize() { if (!array_key_exists('X_ALLOW_TEST_AUTH', $_SERVER) || $_SERVER['X_ALLOW_TEST_AUTH'] != 'true') { return; } $data = ['eduPersonPrincipalName' => Input::get('eduPersonPrincipalName'), 'eduPersonScopedAffiliation' => Input::get('eduPersonScopedAffiliation'), 'sn' => Input::get('sn'), 'givenName' => Input::get('givenName'), 'mail' => Input::get('mail')]; $user = (object) $data; $userId = Input::get('eduPersonPrincipalName'); $owner = Owner::find($userId); if (!$owner) { $owner = new Owner(); $owner->id = $userId; } $owner->data = json_encode($user); $owner->save(); $params = Session::get('authorize-params'); $params['user_id'] = $user->eduPersonPrincipalName; if (Input::get('approve') !== null) { $code = AuthorizationServer::newAuthorizeRequest('user', $params['user_id'], $params); Session::forget('authorize-params'); return Redirect::to(AuthorizationServer::makeRedirectWithCode($code, $params)); } if (Input::get('deny') !== null) { Session::forget('authorize-params'); $url = AuthorizationServer::makeRedirectWithError($params); return new \Illuminate\Http\RedirectResponse((string) $url, 302, array()); } }
/** @test */ function it_checks_if_owner_is_same_with_given() { $john = Owner::find(1); $jane = Owner::find(2); $ownable = $this->getOwnable(); $this->assertFalse($ownable->isOwnedBy($john)); $ownable->associateOwner($john); $this->assertTrue($ownable->isOwnedBy($john)); $this->assertFalse($ownable->isOwnedBy($jane)); }
/** @test */ public function it_changes_owner() { $ownable = $this->getOwnable(); $john = Owner::find(1); $jane = Owner::find(2); $this->assertNull($ownable->getOwner()); $ownable->changeOwnerTo($john); $this->assertEquals($ownable->getOwner(), $john); $ownable->changeOwnerTo($jane); $this->assertEquals($ownable->getOwner(), $jane); }
public function create_manual_request() { $latitude = Input::get('latitude'); $longitude = Input::get('longitude'); $d_latitude = Input::get('d_latitude'); $d_longitude = Input::get('d_longitude'); $type = Input::get('type'); $provider = Input::get('provider'); $user_id = Session::get('user_id'); $time = date("Y-m-d H:i:s"); $provider_details = Walker::where('id', '=', $provider)->first(); $user = Owner::where('id', '=', $user_id)->first(); $request = new Requests(); $request->owner_id = $user_id; $request->request_start_time = $time; $request->confirmed_walker = $provider; if ($d_longitude != '' && $d_latitude != '') { $request->D_latitude = $d_latitude; $request->D_longitude = $d_longitude; } $request->current_walker = $provider; $request->status = 1; $request->save(); $reqid = $request->id; $request_service = new RequestServices(); $request_service->type = $type; $request_service->request_id = $request->id; $request_service->save(); $owner = Owner::find($user_id); $owner->latitude = $latitude; $owner->longitude = $longitude; $owner->save(); $walkerlocation = new WalkLocation(); $walkerlocation->request_id = $request->id; $walkerlocation->distance = 0.0; $walkerlocation->latitude = $latitude; $walkerlocation->longitude = $longitude; $walkerlocation->save(); if ($request->save()) { $current_request = Requests::where('id', '=', $reqid)->first(); return Redirect::to('/user/request-trip'); } }
/** * Remove the specified resource from storage. * DELETE /owners/{id} * * @param int $id * @return Response */ public function destroy($id) { Owner::find($id)->delete(); return Redirect::route('admin.owner'); }
public function schedule_request() { $time = date("Y-m-d H:i:s"); $query = "SELECT id,owner_id,current_walker,TIMESTAMPDIFF(SECOND,request_start_time, '{$time}') as diff from request where status = 0 and is_cancelled = 0"; $results = DB::select(DB::raw($query)); foreach ($results as $result) { $settings = Settings::where('key', 'provider_timeout')->first(); $timeout = $settings->value; if ($result->diff >= $timeout) { // Archiving Old Walker RequestMeta::where('request_id', '=', $result->id)->where('walker_id', '=', $result->current_walker)->update(array('status' => 2)); $request_meta = RequestMeta::where('request_id', '=', $result->id)->where('status', '=', 0)->orderBy('created_at')->first(); // update request if (isset($request_meta->walker_id)) { // assign new walker Requests::where('id', '=', $result->id)->update(array('current_walker' => $request_meta->walker_id, 'request_start_time' => date("Y-m-d H:i:s"))); // Send Notification $walker = Walker::find($request_meta->walker_id); $owner_data = Owner::find($result->owner_id); $msg_array = array(); $msg_array['request_id'] = $result->id; $msg_array['id'] = $request_meta->walker_id; if ($walker) { $msg_array['token'] = $walker->token; } $msg_array['client_profile'] = array(); $msg_array['client_profile']['name'] = $owner_data->first_name . " " . $owner_data->last_name; $msg_array['client_profile']['picture'] = $owner_data->picture; $msg_array['client_profile']['bio'] = $owner_data->bio; $msg_array['client_profile']['address'] = $owner_data->address; $msg_array['client_profile']['phone'] = $owner_data->phone; $title = "New Request"; $message = $msg_array; send_notifications($request_meta->walker_id, "walker", $title, $message); } else { // request ended Requests::where('id', '=', $result->id)->update(array('current_walker' => 0, 'status' => 1)); $settings = Settings::where('key', 'sms_request_unanswered')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $result->id, $pattern); sms_notification(1, 'admin', $pattern); // send email $settings = Settings::where('key', 'email_request_unanswered')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $result->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $result->id, $pattern); $subject = "New Request Unansweres"; email_notification(1, 'admin', $pattern, $subject); } } } }
public function pay_debt() { $token = Input::get('token'); $owner_id = Input::get('id'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { $total = $owner_data->debt; if ($total == 0) { $response_array = array('success' => true); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } $payment_data = Payment::where('owner_id', $owner_id)->where('is_default', 1)->first(); if (!$payment_data) { $payment_data = Payment::where('owner_id', $request->owner_id)->first(); } if ($payment_data) { $customer_id = $payment_data->customer_id; if (Config::get('app.default_payment') == 'stripe') { Stripe::setApiKey(Config::get('app.stripe_secret_key')); try { Stripe_Charge::create(array("amount" => $total * 100, "currency" => "usd", "customer" => $customer_id)); } catch (Stripe_InvalidRequestError $e) { // Invalid parameters were supplied to Stripe's API $ownr = Owner::find($owner_id); $ownr->debt = $total; $ownr->save(); $response_array = array('error' => $e->getMessage()); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } $owner_data->debt = 0; $owner_data->save(); } else { $amount = $total; Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $card_id = $payment_data->card_token; $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); Log::info('result = ' . print_r($result, true)); if ($result->success) { $owner_data->debt = $total; } else { $owner_data->debt = 0; } $owner_data->save(); } } $response_array = array('success' => true); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { /* $var = Keywords::where('id', 2)->first(); $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */ $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.User') . ' ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function request_walk_completed() { if (Request::isMethod('post')) { $request_id = Input::get('request_id'); $token = Input::get('token'); $walker_id = Input::get('id'); $latitude = Input::get('latitude'); $longitude = Input::get('longitude'); $distance = Input::get('distance'); $time = Input::get('time'); $walker = Walker::find($walker_id); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'latitude' => $latitude, 'longitude' => $longitude, 'distance' => $distance, 'time' => $time), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'latitude' => 'required', 'longitude' => 'required', 'distance' => 'required', 'time' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) { // check for token validity if (is_token_active($walker_data->token_expiry) || $is_admin) { // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->confirmed_walker == $walker_id) { if ($request->is_started == 1) { $settings = Settings::where('key', 'default_charging_method_for_users')->first(); $pricing_type = $settings->value; $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; $distance = convert($distance, $unit); $pt = ProviderServices::where('provider_id', $walker_id)->get(); foreach ($pt as $key) { $reqserv = RequestServices::where('request_id', $request_id)->where('type', $key->type)->first(); $base_price = $key->base_price; $price_per_unit_distance = $key->price_per_unit_distance * $distance; $price_per_unit_time = $key->price_per_unit_time * $time; $reqserv->base_price = $base_price; $reqserv->distance_cost = $price_per_unit_distance; $reqserv->time_cost = $price_per_unit_time; $reqserv->total = $base_price + $price_per_unit_distance + $price_per_unit_time; $reqserv->save(); } $rs = RequestServices::where('request_id', $request_id)->get(); $total = 0; foreach ($rs as $key) { Log::info('total = ' . print_r($key->total, true)); $total = $total + $key->total; } $request->is_completed = 1; $request->distance = $distance; $request->time = $time; $request->total = $total; // charge client $ledger = Ledger::where('owner_id', $request->owner_id)->first(); if ($ledger) { $balance = $ledger->amount_earned - $ledger->amount_spent; if ($balance > 0) { if ($total > $balance) { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance; $ledger_temp->save(); $total = $total - $balance; } else { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total; $ledger_temp->save(); $total = 0; } } } if ($total == 0) { $request->is_paid = 1; } else { $payment_data = Payment::where('owner_id', $request->owner_id)->first(); if ($payment_data) { $customer_id = $payment_data->customer_id; try { if (Config::get('app.default_payment') == 'stripe') { $am = round($total) * 100; $sett = Settings::where('key', 'service_fee')->first(); $serviceFee = $sett->value * 100; $amount = $am - $serviceFee; Stripe::setApiKey(Config::get('app.stripe_secret_key')); Stripe_Charge::create(array("amount" => $am, "currency" => "usd", "customer" => $customer_id)); if ($walker->merchant_id != NULL) { $transfer = Stripe_Transfer::create(array("amount" => $amount, "currency" => "usd", "recipient" => $walker->merchant_id, "statement_descriptor" => "UberFoxX")); Log::info('transfer = ' . print_r($transfer, true)); } $request->is_paid = 1; } else { $am = round($total, 2); $sett = Settings::where('key', 'service_fee')->first(); $serviceFee = $sett->value; $amount = $am - $serviceFee; Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $card_id = $payment_data->card_token; if ($walker->merchant_id == NULL) { $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); } else { $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id, 'merchantAccountId' => $walker->merchant_id, 'serviceFeeAmount' => $serviceFee)); } Log::info('result = ' . print_r($result, true)); if ($result->success) { $request->is_paid = 1; } else { $request->is_paid = 0; } } } catch (Exception $e) { $response_array = array('success' => false, 'error' => $e, 'error_code' => 405); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } } $request->card_payment = $total; $request->ledger_payment = $request->total - $total; $request->save(); if ($request->is_paid == 1) { $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_request_unanswered')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%user_mobile%', $owner->phone, $pattern); sms_notification(1, 'admin', $pattern); } $walker = Walker::find($walker_id); $walker->is_available = 1; $walker->save(); $walk_location = new WalkLocation(); $walk_location->latitude = $latitude; $walk_location->longitude = $longitude; $walk_location->request_id = $request_id; $walk_location->save(); // Send Notification $walker = Walker::find($request->confirmed_walker); $walker_data = array(); $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['latitude'] = $walker->latitude; $walker_data['longitude'] = $walker->longitude; $walker_data['type'] = $walker->type; $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ?: 0; $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; $bill = array(); if ($request->is_completed == 1) { $bill['distance'] = convert($request->distance, $unit); $bill['time'] = $request->time; $bill['base_price'] = $request->base_price; $bill['distance_cost'] = $request->distance_cost; $bill['time_cost'] = $request->time_cost; $bill['total'] = $request->total; $bill['is_paid'] = $request->is_paid; } $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'walker' => $walker_data, 'bill' => $bill); $title = "Trip Completed"; $message = $response_array; send_notifications($request->owner_id, "owner", $title, $message); // Send SMS $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_when_provider_completes_job')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern); $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern); $pattern = str_replace('%damount%', $request->total, $pattern); sms_notification($request->owner_id, 'owner', $pattern); // send email $settings = Settings::where('key', 'email_request_finished')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern); $subject = "Request Completed"; email_notification(1, 'admin', $pattern, $subject); $settings = Settings::where('key', 'email_invoice_generated_user')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); $subject = "Invoice Generated"; email_notification($request->owner_id, 'owner', $pattern, $subject); $settings = Settings::where('key', 'email_invoice_generated_provider')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); $subject = "Invoice Generated"; email_notification($request->confirmed_walker, 'walker', $pattern, $subject); if ($request->is_paid == 1) { // send email $settings = Settings::where('key', 'email_payment_charged')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern); $subject = "Payment Charged"; email_notification(1, 'admin', $pattern, $subject); } $response_array = array('success' => true, 'total' => $total, 'is_paid' => $request->is_paid); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Walk not yet started', 'error_code' => 413); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Walk ID doesnot matches with Walker ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Walk ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Walker ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } } $response = Response::json($response_array, $response_code); return $response; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $user = Owner::find($id); return View::make('pages.edit', compact('user')); }
public function user_set_destination() { $request_id = Input::get('request_id'); $token = Input::get('token'); $owner_id = Input::get('id'); $dest_lat = Input::get('dest_lat'); $dest_long = Input::get('dest_long'); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'owner_id' => $owner_id, 'dest_lat' => $dest_lat, 'dest_long' => $dest_long), array('request_id' => 'required|integer', 'token' => 'required', 'owner_id' => 'required|integer', 'dest_lat' => 'required', 'dest_long' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->owner_id == $owner_data->id) { Requests::where('id', $request_id)->update(array('D_latitude' => $dest_lat, 'D_longitude' => $dest_long)); if ($request->current_walker) { $msg_array = array(); $msg_array['request_id'] = $request_id; $msg_array['unique_id'] = 4; $last_destination = Requests::find($request_id); $owner = Owner::find($owner_id); $request_data = array(); $request_data['owner'] = array(); $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name; $request_data['owner']['picture'] = $owner->picture; $request_data['owner']['phone'] = $owner->phone; $request_data['owner']['address'] = $owner->address; $request_data['owner']['latitude'] = $owner->latitude; $request_data['owner']['longitude'] = $owner->longitude; $request_data['owner']['dest_latitude'] = $last_destination->D_latitude; $request_data['owner']['dest_longitude'] = $last_destination->D_longitude; $request_data['owner']['rating'] = $owner->rate; $request_data['owner']['num_rating'] = $owner->rate_count; $request_data['dog'] = array(); if ($dog = Dog::find($owner->dog_id)) { $request_data['dog']['name'] = $dog->name; $request_data['dog']['age'] = $dog->age; $request_data['dog']['breed'] = $dog->breed; $request_data['dog']['likes'] = $dog->likes; $request_data['dog']['picture'] = $dog->image_url; } $msg_array['request_data'] = $request_data; $title = "Set Destination"; $message = $msg_array; if ($request->confirmed_walker == $request->current_walker) { send_notifications($request->confirmed_walker, "walker", $title, $message); } } $response_array = array('success' => true, 'error' => "Destination Set Successfully"); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with Owner ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Request ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function forgot_password() { $type = Input::get('type'); $email = Input::get('email'); if ($type == 1) { // Walker $walker_data = Walker::where('email', $email)->first(); if ($walker_data) { $walker = Walker::find($walker_data->id); $new_password = time(); $new_password .= rand(); $new_password = sha1($new_password); $new_password = substr($new_password, 0, 8); $walker->password = Hash::make($new_password); $walker->save(); // send email $settings = Settings::where('key', 'email_forgot_password')->first(); $pattern = $settings->value; $pattern = str_replace('%password%', $new_password, $pattern); $subject = "Your New Password"; email_notification($walker->id, 'walker', $pattern, $subject); $response_array = array(); $response_array['success'] = true; $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } else { $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } else { $owner_data = Owner::where('email', $email)->first(); if ($owner_data) { $owner = Owner::find($owner_data->id); $new_password = time(); $new_password .= rand(); $new_password = sha1($new_password); $new_password = substr($new_password, 0, 8); $owner->password = Hash::make($new_password); $owner->save(); $settings = Settings::where('key', 'email_forgot_password')->first(); $pattern = $settings->value; $pattern = str_replace('%password%', $new_password, $pattern); $subject = "Your New Password"; email_notification($owner->id, 'owner', $pattern, $subject); $response_array = array(); $response_array['success'] = true; $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } else { $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } }
public function forgot_password() { $type = Input::get('type'); $email = Input::get('email'); if ($type == 1) { // Walker $walker_data = Walker::where('email', $email)->first(); if ($walker_data) { $walker = Walker::find($walker_data->id); $new_password = time(); $new_password .= rand(); $new_password = sha1($new_password); $new_password = substr($new_password, 0, 8); $walker->password = Hash::make($new_password); $walker->save(); /* $subject = "Your New Password"; $email_data = array(); $email_data['password'] = $new_password; send_email($walker->id, 'walker', $email_data, $subject, 'forgotpassword'); */ $settings = Settings::where('key', 'admin_email_address')->first(); $admin_email = $settings->value; $login_url = web_url() . "/provider/signin"; $pattern = array('name' => $walker->first_name . " " . $walker->last_name, 'admin_eamil' => $admin_email, 'new_password' => $new_password, 'login_url' => $login_url); $subject = "Your New Password"; email_notification($walker->id, 'walker', $pattern, $subject, 'forgot_password', "imp"); $response_array = array(); $response_array['success'] = true; $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } else { $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } else { $owner_data = Owner::where('email', $email)->first(); if ($owner_data) { $owner = Owner::find($owner_data->id); $new_password = time(); $new_password .= rand(); $new_password = sha1($new_password); $new_password = substr($new_password, 0, 8); $owner->password = Hash::make($new_password); $owner->save(); /* $subject = "Your New Password"; $email_data = array(); $email_data['password'] = $new_password; send_email($owner->id, 'owner', $email_data, $subject, 'forgotpassword'); */ $settings = Settings::where('key', 'admin_email_address')->first(); $admin_email = $settings->value; $login_url = web_url() . "/user/signin"; $pattern = array('name' => $owner->first_name . " " . $owner->last_name, 'admin_eamil' => $admin_email, 'new_password' => $new_password, 'login_url' => $login_url); $subject = "Your New Password"; email_notification($owner->id, 'owner', $pattern, $subject, 'forgot_password', "imp"); $response_array = array(); $response_array['success'] = true; $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } else { $response_array = array('success' => false, 'error' => 'This Email is not Registered', 'error_code' => 425); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } }
public function update_profile() { $token = Input::get('token'); $owner_id = Input::get('id'); $first_name = Input::get('first_name'); $last_name = Input::get('last_name'); $email = Input::get('email'); $phone = Input::get('phone'); $password = Input::get('password'); $picture = Input::file('picture'); $bio = Input::get('bio'); $address = Input::get('address'); $state = Input::get('state'); $country = Input::get('country'); $zipcode = Input::get('zipcode'); $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id, 'email' => $email, 'picture' => $picture, 'zipcode' => $zipcode), array('token' => 'required', 'owner_id' => 'required|integer', 'email' => 'email', 'picture' => 'mimes:jpeg,bmp,png', 'zipcode' => 'integer')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) { // check for token validity if (is_token_active($owner_data->token_expiry) || $is_admin) { // Do necessary operations $owner = Owner::find($owner_id); if ($first_name) { $owner->first_name = $first_name; } if ($last_name) { $owner->last_name = $last_name; } if ($email) { $owner->email = $email; } if ($phone) { $owner->phone = $phone; } if ($bio) { $owner->bio = $bio; } if ($address) { $owner->address = $address; } if ($state) { $owner->state = $state; } if ($country) { $owner->country = $country; } if ($zipcode) { $owner->zipcode = $zipcode; } if ($password) { $owner->password = Hash::make($password); } if (Input::hasFile('picture')) { // upload image $file_name = time(); $file_name .= rand(); $file_name = sha1($file_name); $ext = Input::file('picture')->getClientOriginalExtension(); Input::file('picture')->move(public_path() . "/uploads", $file_name . "." . $ext); $local_url = $file_name . "." . $ext; // Upload to S3 if (Config::get('app.s3_bucket') != "") { $s3 = App::make('aws')->get('s3'); $pic = $s3->putObject(array('Bucket' => Config::get('app.s3_bucket'), 'Key' => $file_name, 'SourceFile' => public_path() . "/uploads/" . $local_url)); $s3->putObjectAcl(array('Bucket' => Config::get('app.s3_bucket'), 'Key' => $file_name, 'ACL' => 'public-read')); $s3_url = $s3->getObjectUrl(Config::get('app.s3_bucket'), $file_name); } else { $s3_url = asset_url() . '/uploads/' . $local_url; } $owner->picture = $s3_url; } $owner->save(); $response_array = array('success' => true, 'id' => $owner->id, 'first_name' => $owner->first_name, 'last_name' => $owner->last_name, 'phone' => $owner->phone, 'email' => $owner->email, 'picture' => $owner->picture, 'bio' => $owner->bio, 'address' => $owner->address, 'state' => $owner->state, 'country' => $owner->country, 'zipcode' => $owner->zipcode, 'login_by' => $owner->login_by, 'social_unique_id' => $owner->social_unique_id, 'device_token' => $owner->device_token, 'device_type' => $owner->device_type, 'token' => $owner->token); $response_code = 200; } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } $response = Response::json($response_array, $response_code); return $response; }
public function providerTripDetail() { $id = Request::segment(3); $walker_id = Session::get('walker_id'); $request = Requests::find($id); if ($request->confirmed_walker == $walker_id) { $locations = WalkLocation::where('request_id', $id)->orderBy('id')->get(); $start = WalkLocation::where('request_id', $id)->orderBy('id')->first(); $end = WalkLocation::where('request_id', $id)->orderBy('id', 'desc')->first(); $map = "https://maps-api-ssl.google.com/maps/api/staticmap?size=249x249&style=feature:landscape|visibility:off&style=feature:poi|visibility:off&style=feature:transit|visibility:off&style=feature:road.highway|element:geometry|lightness:39&style=feature:road.local|element:geometry|gamma:1.45&style=feature:road|element:labels|gamma:1.22&style=feature:administrative|visibility:off&style=feature:administrative.locality|visibility:on&style=feature:landscape.natural|visibility:on&scale=2&markers=shadow:false|scale:2|icon:http://d1a3f4spazzrp4.cloudfront.net/receipt-new/marker-start@2x.png|{$start->latitude},{$start->longitude}&markers=shadow:false|scale:2|icon:http://d1a3f4spazzrp4.cloudfront.net/receipt-new/marker-finish@2x.png|{$end->latitude},{$end->longitude}&path=color:0x2dbae4ff|weight:4"; foreach ($locations as $location) { $map .= "|{$location->latitude},{$location->longitude}"; } $start_location = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng={$start->latitude},{$start->longitude}"), TRUE); $start_address = $start_location['results'][0]['formatted_address']; $end_location = json_decode(file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng={$end->latitude},{$end->longitude}"), TRUE); $end_address = $end_location['results'][0]['formatted_address']; $owner = Owner::find($request->owner_id); $owner_review = DogReview::where('request_id', $id)->first(); if ($owner_review) { $rating = round($owner_review->rating); } else { $rating = 0; } return View::make('web.providerTripDetail')->with('title', 'My Trips')->with('request', $request)->with('start_address', $start_address)->with('end_address', $end_address)->with('start', $start)->with('end', $end)->with('map_url', $map)->with('owner', $owner)->with('rating', $rating); } else { echo "false"; } }
public function updateUserPassword() { $current_password = Input::get('current_password'); $new_password = Input::get('new_password'); $confirm_password = Input::get('confirm_password'); $owner_id = Session::get('user_id'); $owner = Owner::find($owner_id); if (Hash::check($current_password, $owner->password)) { $password = Hash::make($new_password); $owner->password = $password; $owner->save(); $message = "Your password is successfully updated"; $type = "success"; } else { $message = "Please enter your current password correctly"; $type = "danger"; } return Redirect::to('/user/profile')->with('message', $message)->with('type', $type); }
public function pre_payment() { if (Request::isMethod('post')) { $request_id = Input::get('request_id'); $token = Input::get('token'); $walker_id = Input::get('id'); $time = Input::get('time'); $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'time' => $time), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'time' => 'required')); if ($validator->fails()) { $error_messages = $validator->messages()->all(); $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages); $response_code = 200; } else { $is_admin = $this->isAdmin($token); if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) { // check for token validity if (is_token_active($walker_data->token_expiry) || $is_admin) { // Do necessary operations if ($request = Requests::find($request_id)) { if ($request->confirmed_walker == $walker_id) { $request_service = RequestServices::find($request_id); $request_typ = ProviderType::where('id', '=', $request_service->type)->first(); if (!$walker_data->type) { /* $settings = Settings::where('key', 'price_per_unit_distance')->first(); $price_per_unit_distance = $settings->value; $settings = Settings::where('key', 'price_per_unit_time')->first(); $price_per_unit_time = $settings->value; $settings = Settings::where('key', 'base_price')->first(); $base_price = $settings->value; */ $price_per_unit_distance = $request_typ->price_per_unit_distance; $price_per_unit_time = $request_typ->price_per_unit_time; $base_price = $request_typ->base_price; } else { $provider_type = ProviderServices::find($walker_data->type); $base_price = $provider_type->base_price; $price_per_unit_distance = $provider_type->price_per_unit_distance; $price_per_unit_time = $provider_type->price_per_unit_time; } $settings = Settings::where('key', 'default_charging_method_for_users')->first(); $pricing_type = $settings->value; $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($pricing_type == 1) { $distance_cost = $price_per_unit_distance; $time_cost = $price_per_unit_time; $total = $base_price + $distance_cost + $time_cost; } else { $distance_cost = 0; $time_cost = 0; $total = $base_price; } Log::info('req'); $request_service = RequestServices::find($request_id); $request_service->base_price = $base_price; $request_service->distance_cost = $distance_cost; $request_service->time_cost = $time_cost; $request_service->total = $total; $request_service->save(); $request->distance = $distance_cost; $request->time = $time_cost; $request->total = $total; Log::info('in '); // charge client $ledger = Ledger::where('owner_id', $request->owner_id)->first(); if ($ledger) { $balance = $ledger->amount_earned - $ledger->amount_spent; if ($balance > 0) { if ($total > $balance) { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance; $ledger_temp->save(); $total = $total - $balance; } else { $ledger_temp = Ledger::find($ledger->id); $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total; $ledger_temp->save(); $total = 0; } } } Log::info('out'); if ($total == 0) { $request->is_paid = 1; } else { $payment_data = Payment::where('owner_id', $request->owner_id)->where('is_default', 1)->first(); if (!$payment_data) { $payment_data = Payment::where('owner_id', $request->owner_id)->first(); } if ($payment_data) { $customer_id = $payment_data->customer_id; try { if (Config::get('app.default_payment') == 'stripe') { Stripe::setApiKey(Config::get('app.stripe_secret_key')); try { Stripe_Charge::create(array("amount" => floor($total) * 100, "currency" => "usd", "customer" => $customer_id)); } catch (Stripe_InvalidRequestError $e) { // Invalid parameters were supplied to Stripe's API $ownr = Owner::find($request->owner_id); $ownr->debt = $total; $ownr->save(); $response_array = array('error' => $e->getMessage()); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } $request->is_paid = 1; $setting = Settings::where('key', 'paypal')->first(); $settng1 = Settings::where('key', 'service_fee')->first(); if ($setting->value == 2 && $walker_data->merchant_id != NULL) { // dd($amount$request->transfer_amount); $transfer = Stripe_Transfer::create(array("amount" => ($total - $settng1->value) * 100, "currency" => "usd", "recipient" => $walker_data->merchant_id)); } } else { $amount = $total; Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $card_id = $payment_data->card_token; $setting = Settings::where('key', 'paypal')->first(); $settng1 = Settings::where('key', 'service_fee')->first(); if ($setting->value == 2 && $walker_data->merchant_id != NULL) { // escrow $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); } else { $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id)); } Log::info('result = ' . print_r($result, true)); if ($result->success) { $request->is_paid = 1; } else { $request->is_paid = 0; } } } catch (Exception $e) { $response_array = array('success' => false, 'error' => $e, 'error_code' => 405); $response_code = 200; $response = Response::json($response_array, $response_code); return $response; } } } $request->card_payment = $total; $request->ledger_payment = $request->total - $total; $request->save(); Log::info('Request = ' . print_r($request, true)); if ($request->is_paid == 1) { $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_request_unanswered')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%user_mobile%', $owner->phone, $pattern); sms_notification(1, 'admin', $pattern); } $walker = Walker::find($walker_id); $walker->is_available = 1; $walker->save(); // Send Notification $walker = Walker::find($request->confirmed_walker); $walker_data = array(); $walker_data['first_name'] = $walker->first_name; $walker_data['last_name'] = $walker->last_name; $walker_data['phone'] = $walker->phone; $walker_data['bio'] = $walker->bio; $walker_data['picture'] = $walker->picture; $walker_data['type'] = $walker->type; $walker_data['rating'] = $walker->rate; $walker_data['num_rating'] = $walker->rate_count; $walker_data['car_model'] = $walker->car_model; $walker_data['car_number'] = $walker->car_number; /* $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0; $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */ $settings = Settings::where('key', 'default_distance_unit')->first(); $unit = $settings->value; if ($unit == 0) { $unit_set = 'kms'; } elseif ($unit == 1) { $unit_set = 'miles'; } $bill = array(); if ($request->is_paid == 1) { $bill['distance'] = (string) convert($request->distance, $unit); $bill['unit'] = $unit_set; $bill['time'] = $request->time; $bill['base_price'] = currency_converted($base_price); $bill['distance_cost'] = currency_converted($distance_cost); $bill['time_cost'] = currency_converted($time_cost); $bill['total'] = currency_converted($request->total); $bill['is_paid'] = $request->is_paid; } $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'walker' => $walker_data, 'bill' => $bill); $title = "Payment Has Made"; $message = $response_array; send_notifications($walker->id, "walker", $title, $message); $settings = Settings::where('key', 'email_notification')->first(); $condition = $settings->value; if ($condition == 1) { /* $settings = Settings::where('key', 'payment_made_client')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); $subject = "Payment Charged"; email_notification($walker->id, 'walker', $pattern, $subject); */ $settings = Settings::where('key', 'admin_email_address')->first(); $admin_email = $settings->value; $pattern = array('admin_eamil' => $admin_email, 'name' => ucwords($walker->first_name . " " . $walker->last_name), 'amount' => $total, 'req_id' => $request_id, 'web_url' => web_url()); $subject = "Payment Done With " . $request_id . ""; email_notification($walker->id, 'walker', $pattern, $subject, 'pre_payment', null); } // Send SMS $owner = Owner::find($request->owner_id); $settings = Settings::where('key', 'sms_when_provider_completes_job')->first(); $pattern = $settings->value; $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern); $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern); $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern); $pattern = str_replace('%amount%', $request->total, $pattern); sms_notification($request->owner_id, 'owner', $pattern); $email_data = array(); $email_data['name'] = $owner->first_name; $email_data['emailType'] = 'user'; $email_data['base_price'] = $bill['base_price']; $email_data['distance'] = $bill['distance']; $email_data['time'] = $bill['time']; $email_data['unit'] = $bill['unit']; $email_data['total'] = $bill['total']; if ($bill['payment_mode']) { $email_data['payment_mode'] = $bill['payment_mode']; } else { $email_data['payment_mode'] = '---'; } /* $subject = "Invoice Generated"; send_email($request->owner_id, 'owner', $email_data, $subject, 'invoice'); $subject = "Invoice Generated"; $email_data['emailType'] = 'walker'; send_email($request->confirmed_walker, 'walker', $email_data, $subject, 'invoice'); */ if ($request->is_paid == 1) { // send email /* $settings = Settings::where('key', 'email_payment_charged')->first(); $pattern = $settings->value; $pattern = str_replace('%id%', $request->id, $pattern); $pattern = str_replace('%url%', web_url() . "/admin/request/" . $request->id, $pattern); $subject = "Payment Charged"; email_notification(1, 'admin', $pattern, $subject); */ $settings = Settings::where('key', 'admin_email_address')->first(); $admin_email = $settings->value; $pattern = array('admin_eamil' => $admin_email, 'name' => 'Administrator', 'amount' => $total, 'req_id' => $request_id, 'web_url' => web_url()); $subject = "Payment Done With " . $request_id . ""; email_notification(1, 'admin', $pattern, $subject, 'pay_charged', null); } $response_array = array('success' => true, 'base_fare' => currency_converted($base_price), 'distance_cost' => currency_converted($distance_cost), 'time_cost' => currency_converted($time_cost), 'total' => currency_converted($total), 'is_paid' => $request->is_paid); $response_code = 200; } else { /* $var = Keywords::where('id', 1)->first(); $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . $var->keyword . ' ID', 'error_code' => 407); */ $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . Config::get('app.generic_keywords.Provider') . ' ID', 'error_code' => 407); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Service ID Not Found', 'error_code' => 408); $response_code = 200; } } else { $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405); $response_code = 200; } } else { if ($is_admin) { /* $var = Keywords::where('id', 1)->first(); $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */ $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.Provider') . ' ID not Found', 'error_code' => 410); } else { $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406); } $response_code = 200; } } } $response = Response::json($response_array, $response_code); return $response; }
function send_notifications($id, $type, $title, $message, $is_imp = NULL) { Log::info('push notification'); $settings = Settings::where('key', 'push_notification')->first(); $push_notification = $settings->value; if ($type == 'walker') { $user = Walker::find($id); } else { $user = Owner::find($id); } if ($push_notification == 1 || $is_imp == "imp") { if ($user->device_type == 'ios') { /* WARNING:- you can't pass devicetoken as string in GCM or IOS push * you have to pass array of devicetoken even thow it's only one device's token. */ /* send_ios_push("E146C7DCCA5EBD49803278B3EE0C1825EF0FA6D6F0B1632A19F783CB02B2617B",$title,$message,$type); */ send_ios_push($user->device_token, $title, $message, $type); } else { $message = json_encode($message); send_android_push($user->device_token, $title, $message); } } }
public function alternative_walkers_xml() { $id = Request::segment(4); $walk = Walk::find($id); $schedule = Schedules::find($walk->schedule_id); $dog = Dog::find($walk->dog_id); $owner = Owner::find($dog->owner_id); $current_walker = Walker::find($walk->walker_id); $latitude = $owner->latitude; $longitude = $owner->longitude; $distance = 5; // Get Latitude $schedule_meta = ScheduleMeta::where('schedule_id', '=', $schedule->id)->orderBy('started_on', 'DESC')->paginate(10); $flag = 0; $date = "0000-00-00"; $days = array(); foreach ($schedule_meta as $meta) { if ($flag == 0) { $date = $meta->started_on; $flag++; } array_push($days, $meta->day); } $start_time = date('H:i:s', strtotime($schedule->start_time) - 60 * 60); $end_time = date('H:i:s', strtotime($schedule->end_time) + 60 * 60); $days_str = implode(',', $days); $query = "SELECT walker.id,walker.bio,walker.first_name,walker.last_name,walker.phone,walker.latitude,walker.longitude from walker where id NOT IN ( SELECT distinct schedules.walker_id FROM `schedule_meta` left join schedules on schedule_meta.schedule_id = schedules.id where schedules.is_confirmed\t != 0 and schedule_meta.day IN ({$days_str}) and schedule_meta.ends_on >= '{$date}' and schedule_meta.started_on <= '{$date}' and ((schedules.start_time > '{$start_time}' and schedules.start_time < '{$end_time}') OR ( schedules.end_time > '{$start_time}' and schedules.end_time < '{$end_time}' )) ) and (1.609344 * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) <= {$distance} "; $walkers = DB::select(DB::raw($query)); $response = ""; $response .= '<markers>'; foreach ($walkers as $walker) { $response .= '<marker '; $response .= 'name="' . $walker->first_name . " " . $walker->last_name . '" '; $response .= 'client_name="' . $walker->first_name . " " . $walker->last_name . '" '; $response .= 'contact="' . $walker->phone . '" '; $response .= 'amount="' . 0 . '" '; $response .= 'lat="' . $walker->latitude . '" '; $response .= 'lng="' . $walker->longitude . '" '; $response .= 'id="' . $walker->id . '" '; $response .= 'type="client" '; $response .= '/>'; } // Add Current walker if ($current_walker) { $response .= '<marker '; $response .= 'name="' . $current_walker->first_name . " " . $current_walker->last_name . '" '; $response .= 'client_name="' . $current_walker->first_name . " " . $current_walker->last_name . '" '; $response .= 'contact="' . $current_walker->phone . '" '; $response .= 'amount="' . 0 . '" '; $response .= 'lat="' . $current_walker->latitude . '" '; $response .= 'lng="' . $current_walker->longitude . '" '; $response .= 'id="' . $current_walker->id . '" '; $response .= 'type="driver" '; $response .= '/>'; } // Add Owner $response .= '<marker '; $response .= 'name="' . $owner->first_name . " " . $owner->last_name . '" '; $response .= 'client_name="' . $owner->first_name . " " . $owner->last_name . '" '; $response .= 'contact="' . $owner->phone . '" '; $response .= 'amount="' . 0 . '" '; $response .= 'lat="' . $owner->latitude . '" '; $response .= 'lng="' . $owner->longitude . '" '; $response .= 'id="' . $owner->id . '" '; $response .= 'type="client_pay_done" '; $response .= '/>'; // Add Busy Walkers $walkers = DB::table('request')->where('walk.is_started', 1)->where('walk.is_completed', 0)->join('walker', 'walk.walker_id', '=', 'walker.id')->select('walker.id', 'walker.phone', 'walker.first_name', 'walker.last_name', 'walker.latitude', 'walker.longitude')->distinct()->paginate(10); foreach ($walkers as $walker) { $response .= '<marker '; $response .= 'name="' . $walker->first_name . " " . $walker->last_name . '" '; $response .= 'client_name="' . $walker->first_name . " " . $walker->last_name . '" '; $response .= 'contact="' . $walker->phone . '" '; $response .= 'amount="' . 0 . '" '; $response .= 'lat="' . $walker->latitude . '" '; $response .= 'lng="' . $walker->longitude . '" '; $response .= 'id="' . $owner->id . '" '; $response .= 'type="client_no_pay" '; $response .= '/>'; } $response .= '</markers>'; $content = View::make('walkers_xml')->with('response', $response); return Response::make($content, '200')->header('Content-Type', 'text/xml'); }