dealhub/app/Http/Controllers/Broker/BrokerProfileController.php
kusowl 94ef8f360d feature (favorite and reported deals):
- add favorites and reported tabs in user profile pages
- add remove favorites
- customers can view a deal directly from profiles section and deal modal is shown in explore page
- fix formatting by pint
2026-01-23 16:14:04 +05:30

91 lines
2.6 KiB
PHP

<?php
namespace App\Http\Controllers\Broker;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreBrokerProfileRequest;
use App\Models\Broker;
use App\Models\User;
use App\Services\ProfileInitialsService;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class BrokerProfileController extends Controller
{
/**
* Display the specified resource.
*/
public function show(User $profile, ProfileInitialsService $service)
{
// Get the broker profile
$broker = $profile->type;
// TODO: move this to middleware
if (! $broker instanceof Broker) {
abort(403, 'This user is not a broker.');
}
$initials = $service->create($profile->name);
return view('dashboards.broker.profile.show')
->with('name', $profile->name)
->with('joinDate', $profile->created_at->format('F Y'))
->with('email', $profile->email)
->with('initials', $initials)
->with('verified', $broker->verified)
->with('location', $broker->location)
->with('bio', $broker->bio)
->with('phone', $broker->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());
$userData = $data->only($userFields)->toArray();
$brokerData = $data->except($userFields)->toArray();
try {
DB::transaction(function () use ($profile, $userData, $brokerData) {
$profile->update($userData);
$broker = $profile->type;
Broker::unguard();
$broker->update($brokerData);
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.');
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}