dealhub/app/Http/Controllers/User/UserProfileController.php
kusowl 690a50408d feature(admin-panel): add manage customer page
- list customer
- edit customer details
- delete customer
2026-01-27 17:18:50 +05:30

74 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\User;
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\Log;
class UserProfileController extends Controller
{
/**
* Display the specified resource.
*/
public function show(
User $profile,
ProfileInitialsService $service,
GetUserFavoritesAction $favoritesAction,
GetUserReportedDealsAction $reportedDealsAction
) {
// Get the user profile
$user = $profile->type;
$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('location', $user->location)
->with('bio', $user->bio)
->with('phone', $user->phone)
->with('favorites', $favoritesAction->execute($profile))
->with('reported', $reportedDealsAction->execute($profile));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(User $profile)
{
return view('dashboards.user.profile.edit')
->with('profile', $profile)
->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, UpdateCustomerAction $action)
{
try {
$action->execute($request->validated(), $profile);
return to_route('customer.profile.show', $profile)
->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.');
}
}
}