- Removed `UserDashboardController` and related user dashboard views. - Introduced `ExplorePageController` and redesigned `explore.blade.php` as the main user-facing page. - Updated routing logic to redirect users (non-admin and non-broker) to the `explore` page. - Added dedicated sidebar and layout components for the broker dashboard, improving structure and navigation.
98 lines
2.9 KiB
PHP
98 lines
2.9 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 Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Str;
|
|
|
|
class BrokerProfileController extends Controller
|
|
{
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(User $profile)
|
|
{
|
|
// Get the broker profile
|
|
$broker = $profile->type;
|
|
|
|
// TODO: move this to middleware
|
|
if (! $broker instanceof Broker) {
|
|
abort(403, 'This user is not a broker.');
|
|
}
|
|
|
|
/**
|
|
* Create the initials from a full name (e.g. John Doe, Alex Mark, jane clerk)
|
|
* to display on profile page (e.g. JD, AM, JC).
|
|
*/
|
|
$initials = Str::of($profile->name)
|
|
->explode(' ')
|
|
->map(fn ($word) => Str::substr(ucfirst($word), 0, 1))
|
|
->join('');
|
|
|
|
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)
|
|
{
|
|
//
|
|
}
|
|
}
|