dealhub/app/Http/Controllers/User/UserProfileController.php
kusowl 193913dfad fix: controller namespaces
- change 'auth' to Auth
- fix use statements to correctly
2026-01-22 17:38:50 +05:30

79 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreBrokerProfileRequest;
use App\Models\Broker;
use App\Models\User;
use App\Services\ProfileInitialsService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class UserProfileController extends Controller
{
/**
* Display the specified resource.
*/
public function show(User $profile, ProfileInitialsService $service)
{
// Get the user profile
$user = $profile->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.');
}
}
}