type; // TODO: move this to middleware if (! $broker instanceof Broker) { abort(403, 'This user is not a broker.'); } $initials = $service->create($profile->name); return view('dashboards.broker.profile.show') ->with('name', $profile->name) ->with('joinDate', $profile->created_at->format('F Y')) ->with('email', $profile->email) ->with('initials', $initials) ->with('verified', $broker->verified) ->with('location', $broker->location) ->with('bio', $broker->bio) ->with('phone', $broker->phone); } /** * Show the form for editing the specified resource. */ public function edit(User $profile) { return view('dashboards.broker.profile.edit') ->with('profile', $profile) ->with('broker', $profile->type); } /** * Update the specified resource in storage. */ public function update(StoreBrokerProfileRequest $request, User $profile) { /** * Separate the user fields from the broker fields */ $userFields = ['name', 'email']; $data = collect($request->validated()); $userData = $data->only($userFields)->toArray(); $brokerData = $data->except($userFields)->toArray(); try { DB::transaction(function () use ($profile, $userData, $brokerData) { $profile->update($userData); $broker = $profile->type; Broker::unguard(); $broker->update($brokerData); Broker::reguard(); }); return to_route('broker.profile.show', $profile) ->with('success', 'Profile updated successfully.'); } catch (\Throwable $e) { Log::error('Broker Profile Update Failed: '.$e->getMessage(), $e->getTrace()); return back()->withInput()->with('error', 'Something went wrong.'); } } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }