type; $initials = $service->create($profile->name); return view('dashboards.user.profile.show') ->with('user', $profile) ->with('name', $profile->name) ->with('joinDate', $profile->created_at->format('F Y')) ->with('email', $profile->email) ->with('initials', $initials) ->with('location', $user->location) ->with('bio', $user->bio) ->with('phone', $user->phone) ->with('favorites', $favoritesAction->execute($profile)) ->with('reported', $reportedDealsAction->execute($profile)); } /** * Show the form for editing the specified resource. */ public function edit(User $profile) { return view('dashboards.user.profile.edit') ->with('profile', $profile) ->with('broker', $profile->type); } /** * Update the specified resource in storage. */ public function update(StoreCustomerProfileRequest $request, User $profile) { /** * Separate the user fields from the broker fields */ $userFields = ['name', 'email']; $data = collect($request->validated()); $profileData = $data->only($userFields)->toArray(); $userData = $data->except($userFields)->toArray(); try { DB::transaction(function () use ($profileData, $profile, $userData) { $profile->update($profileData); $user = $profile->type; $user->update($userData); }); return to_route('customer.profile.show', $profile) ->with('success', 'Profile updated successfully.'); } catch (\Throwable $e) { Log::error('Customer Profile Update Failed: '.$e->getMessage(), $e->getTrace()); return back()->withInput()->with('error', 'Something went wrong.'); } } }