From 193913dfad1b1f4534b6d817c5b525354e28f198 Mon Sep 17 00:00:00 2001 From: kusowl Date: Thu, 22 Jan 2026 17:38:50 +0530 Subject: [PATCH] fix: controller namespaces - change 'auth' to Auth - fix use statements to correctly --- .../AuthenticatedUserController.php | 0 .../RegisteredUserController.php | 2 +- .../Broker/BrokerProfileController.php | 12 +-- .../Controllers/ExplorePageController.php | 13 ++-- .../User/UserProfileController.php | 78 +++++++++++++++++++ app/Services/ProfileInitialsService.php | 21 +++++ .../dashboards/user/profile/edit.blade.php | 39 ++++++++++ .../dashboards/user/profile/show.blade.php | 71 +++++++++++++++++ routes/api/interactions.php | 2 +- routes/web.php | 1 + routes/web/auth.php | 4 +- routes/web/user.php | 12 +++ 12 files changed, 236 insertions(+), 19 deletions(-) rename app/Http/Controllers/{auth => Auth}/AuthenticatedUserController.php (100%) rename app/Http/Controllers/{auth => Auth}/RegisteredUserController.php (97%) create mode 100644 app/Http/Controllers/User/UserProfileController.php create mode 100644 app/Services/ProfileInitialsService.php create mode 100644 resources/views/dashboards/user/profile/edit.blade.php create mode 100644 resources/views/dashboards/user/profile/show.blade.php create mode 100644 routes/web/user.php diff --git a/app/Http/Controllers/auth/AuthenticatedUserController.php b/app/Http/Controllers/Auth/AuthenticatedUserController.php similarity index 100% rename from app/Http/Controllers/auth/AuthenticatedUserController.php rename to app/Http/Controllers/Auth/AuthenticatedUserController.php diff --git a/app/Http/Controllers/auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php similarity index 97% rename from app/Http/Controllers/auth/RegisteredUserController.php rename to app/Http/Controllers/Auth/RegisteredUserController.php index 8c12881..2853540 100644 --- a/app/Http/Controllers/auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -1,6 +1,6 @@ type; @@ -25,14 +26,7 @@ public function show(User $profile) abort(403, 'This user is not a broker.'); } - /** - * Create the initials from a full name (e.g. John Doe, Alex Mark, jane clerk) - * to display on profile page (e.g. JD, AM, JC). - */ - $initials = Str::of($profile->name) - ->explode(' ') - ->map(fn ($word) => Str::substr(ucfirst($word), 0, 1)) - ->join(''); + $initials = $service->create($profile->name); return view('dashboards.broker.profile.show') ->with('name', $profile->name) diff --git a/app/Http/Controllers/ExplorePageController.php b/app/Http/Controllers/ExplorePageController.php index 81feea8..717437c 100644 --- a/app/Http/Controllers/ExplorePageController.php +++ b/app/Http/Controllers/ExplorePageController.php @@ -33,7 +33,7 @@ protected function deals(FormRequest $request, Builder $query, AddRecentSearchAc { // Add a search query if ($request->has('search') && $request->get('search') !== null) { - $query->tap(fn ($q) => (new Deal)->search($q, $request->search)); + $query->tap(fn($q) => (new Deal)->search($q, $request->search)); \Illuminate\Support\defer(function () use ($action, $request) { $action->execute($request->user(), ['query' => $request->search]); @@ -42,7 +42,7 @@ protected function deals(FormRequest $request, Builder $query, AddRecentSearchAc // Add category sorting filter if ($request->has('category') && $request->get('category') !== null) { - $query->tap(fn ($q) => (new Deal)->filterByCategory($q, $request->category)); + $query->tap(fn($q) => (new Deal)->filterByCategory($q, $request->category)); } // Add sorting filters @@ -68,11 +68,12 @@ protected function deals(FormRequest $request, Builder $query, AddRecentSearchAc protected function profileLink(): string { $user = Auth::user(); - if ($user->role === UserTypes::Broker->value) { - return route('broker.profile.show', $user); - } - return ''; + return match ($user->role) { + UserTypes::Broker->value => route('broker.profile.show', $user), + UserTypes::User->value => route('user.profile.show', $user), + default => '' + }; } protected function categories(): Collection diff --git a/app/Http/Controllers/User/UserProfileController.php b/app/Http/Controllers/User/UserProfileController.php new file mode 100644 index 0000000..9c01ba9 --- /dev/null +++ b/app/Http/Controllers/User/UserProfileController.php @@ -0,0 +1,78 @@ +type; + + $initials = $service->create($profile->name); + + return view('dashboards.user.profile.show') + ->with('name', $profile->name) + ->with('joinDate', $profile->created_at->format('F Y')) + ->with('email', $profile->email) + ->with('initials', $initials) + ->with('verified', $user->verified) + ->with('location', $user->location) + ->with('bio', $user->bio) + ->with('phone', $user->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()); + $profileData = $data->only($userFields)->toArray(); + $userData = $data->except($userFields)->toArray(); + + try { + DB::transaction(function () use ($profile, $userData) { + $profile->update($userData); + $user = $profile->type; + + Broker::unguard(); + $user->update($userData); + 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.'); + } + } +} diff --git a/app/Services/ProfileInitialsService.php b/app/Services/ProfileInitialsService.php new file mode 100644 index 0000000..7032af0 --- /dev/null +++ b/app/Services/ProfileInitialsService.php @@ -0,0 +1,21 @@ +explode(' ') + ->map(fn($word) => Str::substr(ucfirst($word), 0, 1)) + ->join(''); + } +} diff --git a/resources/views/dashboards/user/profile/edit.blade.php b/resources/views/dashboards/user/profile/edit.blade.php new file mode 100644 index 0000000..500134c --- /dev/null +++ b/resources/views/dashboards/user/profile/edit.blade.php @@ -0,0 +1,39 @@ + + + + +
+ +

Profile Information

+
+ @csrf + @method('PATCH') + + + + + + + + + + + +
+ Update + Cancel + +
+ +
+
+
diff --git a/resources/views/dashboards/user/profile/show.blade.php b/resources/views/dashboards/user/profile/show.blade.php new file mode 100644 index 0000000..d8cbb04 --- /dev/null +++ b/resources/views/dashboards/user/profile/show.blade.php @@ -0,0 +1,71 @@ + + + + + + + + + + + + + +
+
+ +
+ +
+
+ {{$initials}} +
+
+ +
+ +
+

{{$name ?? 'Name'}}

+
+ {{$verified ? 'Verified Broker' : 'Not Verified'}} + +

4.8

+
+
+ +
+

{{$bio ?? 'Bio is empty'}}

+
+ +
+
+ +

{{$email ?? 'email is empty'}}

+
+
+ +

{{$phone ?? 'phone is empty'}}

+
+
+ +

{{$location ?? 'location is empty'}}

+
+
+ +

Joined {{$joinDate ?? 'date is empty'}}

+
+
+
+
+
+
+
+
diff --git a/routes/api/interactions.php b/routes/api/interactions.php index 3f3eac8..e158f3d 100644 --- a/routes/api/interactions.php +++ b/routes/api/interactions.php @@ -1,6 +1,6 @@ middleware('throttle:30,1') diff --git a/routes/web.php b/routes/web.php index 521431c..783d595 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,6 +9,7 @@ require __DIR__.'/web/auth.php'; require __DIR__.'/web/broker.php'; require __DIR__.'/web/interaction.php'; +require __DIR__.'/web/user.php'; Route::get('/', HomeController::class)->name('home'); Route::middleware('auth')->group(function () { diff --git a/routes/web/auth.php b/routes/web/auth.php index ff129ae..143fd08 100644 --- a/routes/web/auth.php +++ b/routes/web/auth.php @@ -1,7 +1,7 @@ group(function () { Route::resource('/login', AuthenticatedUserController::class) diff --git a/routes/web/user.php b/routes/web/user.php new file mode 100644 index 0000000..f84476f --- /dev/null +++ b/routes/web/user.php @@ -0,0 +1,12 @@ +name('user.') + ->middleware([HasRole::class.':'.UserTypes::User->value, 'auth']) + ->group(function () { + Route::resource('profile', UserProfileController::class)->except('index', 'store', 'create'); + });