From 4f34c5b595c8d507a659f7f8c6865c2bc1fcba3c Mon Sep 17 00:00:00 2001 From: kusowl Date: Thu, 22 Jan 2026 19:06:59 +0530 Subject: [PATCH] feature(customer profile): add show and edit page for customer profile --- .../Auth/RegisteredUserController.php | 26 +++++++++----- .../Controllers/ExplorePageController.php | 2 +- .../Interaction/InteractionController.php | 2 -- .../User/UserProfileController.php | 18 +++++----- .../Requests/StoreCustomerProfileRequest.php | 33 +++++++++++++++++ app/Models/Customer.php | 15 ++++++++ app/Models/User.php | 6 +++- ...26_01_22_125826_create_customers_table.php | 29 +++++++++++++++ .../dashboards/user/profile/edit.blade.php | 20 +++++------ .../dashboards/user/profile/show.blade.php | 35 ++++++++----------- routes/web.php | 2 +- routes/web/{user.php => customer.php} | 4 +-- 12 files changed, 134 insertions(+), 58 deletions(-) create mode 100644 app/Http/Requests/StoreCustomerProfileRequest.php create mode 100644 app/Models/Customer.php create mode 100644 database/migrations/2026_01_22_125826_create_customers_table.php rename routes/web/{user.php => customer.php} (86%) diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 2853540..7374d52 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\StoreRegisterdUser; use App\Models\Broker; -use App\Models\User; +use App\Models\Customer; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -23,16 +23,24 @@ public function store(StoreRegisterdUser $request) $data = $request->validated(); try { DB::transaction(function () use ($data) { - if ($data['role'] === UserTypes::Broker->value) { - $data['status'] = UserStatus::Pending->value; + switch ($data['role']) { + case UserTypes::Broker->value: + { + $data['status'] = UserStatus::Pending->value; - // Create Broker first, then the User linked to it - $broker = Broker::create(); - $broker->user()->create($data); - } else { - $data['status'] = UserStatus::Active->value; + // Create Broker first, then link the user + $broker = Broker::create(); + $broker->user()->create($data); + break; + } + case UserTypes::User->value: + { + $data['status'] = UserStatus::Active->value; - User::create($data); + $customer = Customer::create(); + $customer->user()->create($data); + break; + } } }); diff --git a/app/Http/Controllers/ExplorePageController.php b/app/Http/Controllers/ExplorePageController.php index 717437c..ec1a1fb 100644 --- a/app/Http/Controllers/ExplorePageController.php +++ b/app/Http/Controllers/ExplorePageController.php @@ -71,7 +71,7 @@ protected function profileLink(): string return match ($user->role) { UserTypes::Broker->value => route('broker.profile.show', $user), - UserTypes::User->value => route('user.profile.show', $user), + UserTypes::User->value => route('customer.profile.show', $user), default => '' }; } diff --git a/app/Http/Controllers/Interaction/InteractionController.php b/app/Http/Controllers/Interaction/InteractionController.php index 0d814a4..824a9ab 100644 --- a/app/Http/Controllers/Interaction/InteractionController.php +++ b/app/Http/Controllers/Interaction/InteractionController.php @@ -100,7 +100,6 @@ public function redirect(Deal $deal) public function view(Deal $deal) { - ds('hi'); try { $interaction = $deal->interactions()->firstOrCreate([ 'type' => InteractionType::View, @@ -110,7 +109,6 @@ public function view(Deal $deal) if (! $interaction->wasRecentlyCreated) { $interaction->increment('count'); } - ds($interaction); } catch (\Throwable $e) { Log::error('Error when view a deal', diff --git a/app/Http/Controllers/User/UserProfileController.php b/app/Http/Controllers/User/UserProfileController.php index 9c01ba9..94e02e7 100644 --- a/app/Http/Controllers/User/UserProfileController.php +++ b/app/Http/Controllers/User/UserProfileController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\StoreBrokerProfileRequest; +use App\Http\Requests\StoreCustomerProfileRequest; use App\Models\Broker; use App\Models\User; use App\Services\ProfileInitialsService; @@ -24,11 +25,11 @@ public function show(User $profile, ProfileInitialsService $service) $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('verified', $user->verified) ->with('location', $user->location) ->with('bio', $user->bio) ->with('phone', $user->phone); @@ -39,7 +40,7 @@ public function show(User $profile, ProfileInitialsService $service) */ public function edit(User $profile) { - return view('dashboards.broker.profile.edit') + return view('dashboards.user.profile.edit') ->with('profile', $profile) ->with('broker', $profile->type); } @@ -47,7 +48,7 @@ public function edit(User $profile) /** * Update the specified resource in storage. */ - public function update(StoreBrokerProfileRequest $request, User $profile) + public function update(StoreCustomerProfileRequest $request, User $profile) { /** * Separate the user fields from the broker fields @@ -58,19 +59,16 @@ public function update(StoreBrokerProfileRequest $request, User $profile) $userData = $data->except($userFields)->toArray(); try { - DB::transaction(function () use ($profile, $userData) { - $profile->update($userData); + DB::transaction(function () use ($profileData, $profile, $userData) { + $profile->update($profileData); $user = $profile->type; - - Broker::unguard(); $user->update($userData); - Broker::reguard(); }); - return to_route('broker.profile.show', $profile) + return to_route('customer.profile.show', $profile) ->with('success', 'Profile updated successfully.'); } catch (\Throwable $e) { - Log::error('Broker Profile Update Failed: '.$e->getMessage(), $e->getTrace()); + Log::error('Customer Profile Update Failed: '.$e->getMessage(), $e->getTrace()); return back()->withInput()->with('error', 'Something went wrong.'); } diff --git a/app/Http/Requests/StoreCustomerProfileRequest.php b/app/Http/Requests/StoreCustomerProfileRequest.php new file mode 100644 index 0000000..a6bdb2c --- /dev/null +++ b/app/Http/Requests/StoreCustomerProfileRequest.php @@ -0,0 +1,33 @@ +user()->isCustomer(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'name' => 'required|string|min:3|max:255', + 'bio' => 'required|string|min:10|max:255', + 'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($this->user()->id)], + 'phone' => 'required|string|min:10|max:255', + 'location' => 'required|string|min:3|max:255', + ]; + } +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php new file mode 100644 index 0000000..39390da --- /dev/null +++ b/app/Models/Customer.php @@ -0,0 +1,15 @@ +morphOne(User::class, 'role'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 3f67aab..029d879 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,7 +4,6 @@ // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Foundation\Auth\User as Authenticatable; @@ -78,4 +77,9 @@ public function recentSearches(): HasMany { return $this->hasMany(RecentSearch::class); } + + public function isCustomer(): bool + { + return $this->type instanceof Customer; + } } diff --git a/database/migrations/2026_01_22_125826_create_customers_table.php b/database/migrations/2026_01_22_125826_create_customers_table.php new file mode 100644 index 0000000..6c9d77b --- /dev/null +++ b/database/migrations/2026_01_22_125826_create_customers_table.php @@ -0,0 +1,29 @@ +id(); + $table->text('bio')->nullable(); + $table->string('location')->nullable(); + $table->string('phone')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('customers'); + } +}; diff --git a/resources/views/dashboards/user/profile/edit.blade.php b/resources/views/dashboards/user/profile/edit.blade.php index 500134c..6d4d989 100644 --- a/resources/views/dashboards/user/profile/edit.blade.php +++ b/resources/views/dashboards/user/profile/edit.blade.php @@ -1,15 +1,13 @@ - - - - -
+ + +

Profile Information

-
@csrf @method('PATCH') @@ -36,4 +34,4 @@ class=" border border-accent-600/20 md:col-span-2">Cancel
- +
diff --git a/resources/views/dashboards/user/profile/show.blade.php b/resources/views/dashboards/user/profile/show.blade.php index d8cbb04..2b68a8c 100644 --- a/resources/views/dashboards/user/profile/show.blade.php +++ b/resources/views/dashboards/user/profile/show.blade.php @@ -1,22 +1,21 @@ - - - - - - + + +
+ - - - +
+
+
-
+
@@ -33,12 +32,6 @@ class="w-25 h-25 rounded-xl bg-linear-150 from-[#305afc] to-[#941dfb] text-5xl t

{{$name ?? 'Name'}}

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

4.8

-
@@ -68,4 +61,4 @@ class="w-25 h-25 rounded-xl bg-linear-150 from-[#305afc] to-[#941dfb] text-5xl t
- + diff --git a/routes/web.php b/routes/web.php index 783d595..ac22608 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,7 +9,7 @@ require __DIR__.'/web/auth.php'; require __DIR__.'/web/broker.php'; require __DIR__.'/web/interaction.php'; -require __DIR__.'/web/user.php'; +require __DIR__.'/web/customer.php'; Route::get('/', HomeController::class)->name('home'); Route::middleware('auth')->group(function () { diff --git a/routes/web/user.php b/routes/web/customer.php similarity index 86% rename from routes/web/user.php rename to routes/web/customer.php index f84476f..db1c309 100644 --- a/routes/web/user.php +++ b/routes/web/customer.php @@ -4,8 +4,8 @@ use App\Http\Controllers\User\UserProfileController; use App\Http\Middleware\HasRole; -Route::prefix('/user') - ->name('user.') +Route::prefix('/customer') + ->name('customer.') ->middleware([HasRole::class.':'.UserTypes::User->value, 'auth']) ->group(function () { Route::resource('profile', UserProfileController::class)->except('index', 'store', 'create');