/** * Display a customer * * @return Response */ public function detail($id = null) { $result = \App\Models\Customer::id($id)->with(['sales', 'myreferrals', 'myreferrals.user'])->first(); if ($result) { return new JSend('success', (array) $result->toArray()); } return new JSend('error', (array) Input::all(), 'ID Tidak Valid.'); }
/** * Invite friend * * @return Response */ public function invite($user_id = null) { if (!Input::has('invitations')) { return new JSend('error', (array) Input::all(), 'Tidak ada data invitations.'); } $invitations = Input::get('invitations'); $errors = new MessageBag(); DB::beginTransaction(); //1. Store mail if (!$errors->count()) { foreach ($invitations as $key => $value) { if (!$errors->count()) { $log_data = new \App\Models\UserInvitationLog(); $log_rules = ['email' => 'required|email']; $validator = Validator::make($value, $log_rules); //if there was log and validator false if (!$validator->passes()) { $errors->add('log', $validator->errors()); } else { $value['user_id'] = $user_id; $log_data = $log_data->fill($value); if (!$log_data->save()) { $errors->add('Log', $log_data->getError()); } } } } } if ($errors->count()) { DB::rollback(); return new JSend('error', (array) Input::all(), $errors); } DB::commit(); $final_costumer = \App\Models\Customer::id($user_id)->with(['myreferrals', 'myreferrals.user'])->first()->toArray(); return new JSend('success', (array) $final_costumer); }
/** * Change password * * @return Response */ public function change() { if (!Input::has('email') || !Input::has('password')) { return new JSend('error', (array) Input::all(), 'Tidak ada data customer.'); } $email = Input::get('email'); $password = Input::get('password'); $errors = new MessageBag(); DB::beginTransaction(); //1. Check Email $customer_data = \App\Models\Customer::email($email)->notSSOMedia(['facebook'])->first(); if (!$customer_data) { $errors->add('Customer', 'Email tidak valid.'); } elseif (empty($customer_data->reset_password_link)) { $errors->add('Customer', 'Email tidak valid.'); } else { //if validator passed, save customer $customer_data = $customer_data->fill(['reset_password_link' => '', 'password' => $password, 'date_of_birth' => strtotime($customer_data['date_of_birth']) ? $customer_data['date_of_birth']->format('Y-m-d H:i:s') : '']); if (!$customer_data->save()) { $errors->add('Customer', $customer_data->getError()); } } if ($errors->count()) { DB::rollback(); return new JSend('error', (array) Input::all(), $errors); } DB::commit(); $final_customer = \App\Models\Customer::id($customer_data['id'])->first()->toArray(); return new JSend('success', (array) $final_customer); }