diff --git a/app/Actions/UpdateCustomerAction.php b/app/Actions/UpdateCustomerAction.php
new file mode 100644
index 0000000..145669a
--- /dev/null
+++ b/app/Actions/UpdateCustomerAction.php
@@ -0,0 +1,30 @@
+only($userFields)->toArray();
+ $userData = $data->except($userFields)->toArray();
+
+ DB::transaction(function () use ($profileData, $profile, $userData) {
+ $profile->update($profileData);
+ $user = $profile->type;
+ $user->update($userData);
+ });
+ }
+}
diff --git a/app/Http/Controllers/Admin/CustomerController.php b/app/Http/Controllers/Admin/CustomerController.php
new file mode 100644
index 0000000..e509116
--- /dev/null
+++ b/app/Http/Controllers/Admin/CustomerController.php
@@ -0,0 +1,59 @@
+with('customers', Customer::select(['id', 'location'])
+ ->with('user:id,name,email,role_id,role_type')
+ ->get()
+ );
+ }
+
+ public function edit(Customer $customer)
+ {
+ return view('dashboards.admin.customers.edit')
+ ->with('profile', $customer->user)
+ ->with('backLink', route('admin.customers.index'))
+ ->with('actionLink', route('admin.customers.update', $customer));
+ }
+
+ public function update(StoreCustomerProfileRequest $request, Customer $customer, UpdateCustomerAction $action)
+ {
+ try {
+ $action->execute($request->validated(), $customer->user);
+
+ return to_route('admin.customers.index')
+ ->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.');
+ }
+ }
+
+ public function destroy(Customer $customer)
+ {
+ try {
+ \DB::transaction(function () use ($customer) {
+ $customer->user->delete();
+ $customer->delete();
+ });
+
+ return back()->with('success', 'Customer deleted successfully.');
+ } catch (\Throwable $e) {
+ Log::error('Customer Delete Failed: '.$e->getMessage(), $e->getTrace());
+
+ return back()->with('error', 'Something went wrong.');
+ }
+ }
+}
diff --git a/app/Http/Controllers/ExplorePageController.php b/app/Http/Controllers/ExplorePageController.php
index bd34b7f..9cf1cb5 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
@@ -81,9 +81,10 @@ protected function categories(): Collection
protected function recentSearches(): Collection
{
- if (!Auth::check()) {
+ if (! Auth::check()) {
return collect();
}
- return Auth::user()->recentSearches()->latest()->select(['id','query'])->get();
+
+ return Auth::user()->recentSearches()->latest()->select(['id', 'query'])->get();
}
}
diff --git a/app/Http/Controllers/Interaction/ReportController.php b/app/Http/Controllers/Interaction/ReportController.php
index 37cc512..52ea484 100644
--- a/app/Http/Controllers/Interaction/ReportController.php
+++ b/app/Http/Controllers/Interaction/ReportController.php
@@ -9,7 +9,6 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class ReportController extends Controller
diff --git a/app/Http/Controllers/RecentSearchController.php b/app/Http/Controllers/RecentSearchController.php
index 2672893..520d964 100644
--- a/app/Http/Controllers/RecentSearchController.php
+++ b/app/Http/Controllers/RecentSearchController.php
@@ -8,7 +8,8 @@ class RecentSearchController extends Controller
{
public function __invoke(RecentSearch $recentSearch)
{
- $recentSearch->delete();
- return response()->json(['message' => 'Search deleted successfully.']);
+ $recentSearch->delete();
+
+ return response()->json(['message' => 'Search deleted successfully.']);
}
}
diff --git a/app/Http/Controllers/User/UserProfileController.php b/app/Http/Controllers/User/UserProfileController.php
index d2ca10c..6275b1e 100644
--- a/app/Http/Controllers/User/UserProfileController.php
+++ b/app/Http/Controllers/User/UserProfileController.php
@@ -4,11 +4,11 @@
use App\Actions\GetUserFavoritesAction;
use App\Actions\GetUserReportedDealsAction;
+use App\Actions\UpdateCustomerAction;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreCustomerProfileRequest;
use App\Models\User;
use App\Services\ProfileInitialsService;
-use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class UserProfileController extends Controller
@@ -47,28 +47,20 @@ public function edit(User $profile)
{
return view('dashboards.user.profile.edit')
->with('profile', $profile)
- ->with('broker', $profile->type);
+ ->with('pageTitle', 'Edit Profile')
+ ->with('title', 'Edit Your Profile')
+ ->with('description', 'Update your profile information.')
+ ->with('backLink', route('customer.profile.show', $profile))
+ ->with('actionLink', route('customer.profile.update', $profile));
}
/**
* Update the specified resource in storage.
*/
- public function update(StoreCustomerProfileRequest $request, User $profile)
+ public function update(StoreCustomerProfileRequest $request, User $profile, UpdateCustomerAction $action)
{
- /**
- * 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);
- });
+ $action->execute($request->validated(), $profile);
return to_route('customer.profile.show', $profile)
->with('success', 'Profile updated successfully.');
diff --git a/app/Http/Requests/StoreCustomerProfileRequest.php b/app/Http/Requests/StoreCustomerProfileRequest.php
index a6bdb2c..adece1d 100644
--- a/app/Http/Requests/StoreCustomerProfileRequest.php
+++ b/app/Http/Requests/StoreCustomerProfileRequest.php
@@ -2,9 +2,11 @@
namespace App\Http\Requests;
+use AllowDynamicProperties;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
+#[AllowDynamicProperties]
class StoreCustomerProfileRequest extends FormRequest
{
/**
@@ -12,7 +14,17 @@ class StoreCustomerProfileRequest extends FormRequest
*/
public function authorize(): bool
{
- return $this->user()->isCustomer();
+ // If this request is by a customer profile, then only allow the owner to update it.
+ if (isset($this->profile)) {
+ $this->user = $this->profile;
+
+ return $this->user()->id === $this->profile->id;
+ }
+
+ // If this request is by an admin, then allow them to update any profile.
+ $this->user = $this->customer->user;
+
+ return $this->user()->isAdmin();
}
/**
@@ -25,7 +37,7 @@ 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)],
+ '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/resources/views/components/dashboard/user/edit-profile-card.blade.php b/resources/views/components/dashboard/user/edit-profile-card.blade.php
new file mode 100644
index 0000000..dd4df6c
--- /dev/null
+++ b/resources/views/components/dashboard/user/edit-profile-card.blade.php
@@ -0,0 +1,30 @@
+@props(['profile', 'actionLink', 'backLink'])
+
+
+ Profile Information
+
+
diff --git a/resources/views/dashboards/admin/customers/edit.blade.php b/resources/views/dashboards/admin/customers/edit.blade.php
new file mode 100644
index 0000000..de58b0b
--- /dev/null
+++ b/resources/views/dashboards/admin/customers/edit.blade.php
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
diff --git a/resources/views/dashboards/admin/customers/index.blade.php b/resources/views/dashboards/admin/customers/index.blade.php
index bba7e8e..5a3c7fd 100644
--- a/resources/views/dashboards/admin/customers/index.blade.php
+++ b/resources/views/dashboards/admin/customers/index.blade.php
@@ -30,6 +30,7 @@
onsubmit="return confirm('Are you sure to delete this ?')" method="post"
class=" h-full items-center flex justify-center">
@csrf
+ @method('DELETE')
diff --git a/resources/views/dashboards/user/profile/edit.blade.php b/resources/views/dashboards/user/profile/edit.blade.php
index 6d4d989..dfdf89c 100644
--- a/resources/views/dashboards/user/profile/edit.blade.php
+++ b/resources/views/dashboards/user/profile/edit.blade.php
@@ -1,37 +1,10 @@
-
+
-
- Profile Information
-
-
+