customerService = $customerService; } public function account() { $customer = auth()->user()->load(['company','additionalContacts']); $orders = AlacarteOrder::with(['user','items.product'])->where('user_id',$customer->id)->latest()->get(); return view('customer::account')->with('customer',$customer)->with('orders',$orders); } public function updateProfile(UpdateProfileRequest $request) { try { $customer = auth()->user(); $customer->first_name = $request->first_name; $customer->last_name = $request->last_name; $customer->phone = $request->phone; $customer->date_of_birth = $request->date_of_birth; $customer->description = $request->description; $file = $request->file('avatar'); if ($request->hasFile('avatar')) { $this->deleteImage($customer->avatar); $customer->avatar= $this->saveAvatar($file,200,200); } $customer->save(); return response()->json([ 'message' => 'Profile Updated Successfully.' ]); } catch(Exception $e){ return response()->json([ 'message' => $e->getMessage() ], 500); } } public function updateCompanyInfo(UpdateCompanyInfoRequest $request) { try { $customer = auth()->user(); $company = UserCompany::updateOrCreate( [ 'user_id' => $customer->id, ], [ 'company_name' => $request->company_name, 'brand_name' => $request->brand_name, 'storefront' => $request->storefront, 'company_address' => $request->company_address, 'accounts_payable_name' => $request->accounts_payable_name, 'accounts_payable_email' => $request->accounts_payable_email, 'marketing_contact_name' => $request->marketing_contact_name, ] ); $updates = []; if (Cache::has(auth()->user()->id.'_company_info_updates')) { $updates = json_decode(Cache::pull(auth()->user()->id.'_company_info_updates')); } // foreach ($request->additional_contacts as $key => $additional_contact) { // $contact = UserAdditionalContact::updateOrCreate( // [ // 'id' => $additional_contact['id'] ?? null // ], // [ // 'user_id' => $customer->id, // 'name' => $additional_contact['name'], // 'email' => $additional_contact['email'], // 'position' => $additional_contact['position'], // ] // ); // if(!$contact->wasRecentlyCreated && $contact->wasChanged()){ // $changes = \Arr::except($contact->getChanges(), ['updated_at']); // foreach($changes as $attr => $value){ // $updates[] = "Updated Additional Contact ".str_replace(' ', '_', $attr)." to ". $value.""; // } // } // if($contact->wasRecentlyCreated){ // $updates[] = "Added Additional Contact with Name: ". $contact->name.", Email: ". $contact->email." and Position: ".$contact->position.""; // } // } // $contactsId = collect($request->additional_contacts)->pluck('id')->toArray(); // $customer->additionalContacts() // ->whereNotIn('id', $contactsId) // ->delete(); if(count($updates) > 0){ $changes = ''; $changes .= '