with('activeBrokers', Broker::select(['id', 'location']) ->whereRelation('user', 'status', UserStatus::Active->value) ->with('user:id,name,email,role_id,role_type') ->get() ) ->with('pendingBrokers', Broker::select(['id', 'location']) ->whereRelation('user', 'status', UserStatus::Pending->value) ->with('user:id,name,email,role_id,role_type') ->get() ); } public function edit(Broker $broker) { return view('dashboards.admin.brokers.edit') ->with('profile', $broker->user) ->with('backLink', route('admin.brokers.index')) ->with('actionLink', route('admin.brokers.update', $broker)); } public function update(StoreBrokerProfileRequest $request, Broker $broker, UpdateBrokerAction $action) { try { $action->execute($request->validated(), $broker->user); return to_route('admin.brokers.index') ->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.'); } } public function destroy(Broker $broker) { try { \DB::transaction(function () use ($broker) { $broker->user->delete(); $broker->delete(); }); return back()->with('success', 'Broker deleted successfully.'); } catch (\Throwable $e) { Log::error('Broker Delete Failed: ', [$e->getMessage(), $e->getTrace()]); return back()->with('error', 'Something went wrong.'); } } public function approve(Broker $broker) { try { $broker->user->update(['status' => UserStatus::Active->value]); return to_route('admin.brokers.index')->with('success', 'Broker approved successfully.'); } catch (\Throwable $e) { Log::error('Broker Approval Failed: ', [$e->getMessage(), $e->getTrace()]); return back()->with('error', 'Something went wrong.'); } } }