fix: controller namespaces

- change 'auth' to Auth
- fix use statements to correctly
This commit is contained in:
kusowl 2026-01-22 17:38:50 +05:30
parent 4060866b2d
commit 193913dfad
12 changed files with 236 additions and 19 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace App\Http\Controllers\auth;
namespace App\Http\Controllers\Auth;
use App\Enums\UserStatus;
use App\Enums\UserTypes;

View File

@ -6,6 +6,7 @@
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;
use Illuminate\Support\Str;
@ -15,7 +16,7 @@ class BrokerProfileController extends Controller
/**
* Display the specified resource.
*/
public function show(User $profile)
public function show(User $profile, ProfileInitialsService $service)
{
// Get the broker profile
$broker = $profile->type;
@ -25,14 +26,7 @@ public function show(User $profile)
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('');
$initials = $service->create($profile->name);
return view('dashboards.broker.profile.show')
->with('name', $profile->name)

View File

@ -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
@ -68,11 +68,12 @@ protected function deals(FormRequest $request, Builder $query, AddRecentSearchAc
protected function profileLink(): string
{
$user = Auth::user();
if ($user->role === UserTypes::Broker->value) {
return route('broker.profile.show', $user);
}
return '';
return match ($user->role) {
UserTypes::Broker->value => route('broker.profile.show', $user),
UserTypes::User->value => route('user.profile.show', $user),
default => ''
};
}
protected function categories(): Collection

View File

@ -0,0 +1,78 @@
<?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.');
}
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Services;
use Illuminate\Support\Str;
class ProfileInitialsService
{
/**
* Create the initials from a full name (e.g. John Doe, Alex Mark, jane clerk)
* to display on the profile page (e.g. JD, AM, JC).
*/
public function create(string $fullname)
{
return Str::of($fullname)
->explode(' ')
->map(fn($word) => Str::substr(ucfirst($word), 0, 1))
->join('');
}
}

View File

@ -0,0 +1,39 @@
<x-dashboard.broker.layout title="Edit Broker Profile">
<x-slot:heading>
<x-dashboard.page-heading
title="Edit Profile"
description="Modify your profile details"
:back-link="route('broker.profile.show', $profile)"
/>
</x-slot:heading>
<div class="flex items-center justify-center px-4 pb-4 pt-0 md:px-8 md:pb-8">
<x-dashboard.card class="w-full">
<h3 class="text-md font-bold">Profile Information</h3>
<form method="post" enctype="multipart/form-data" action="{{route('broker.profile.update', $profile)}}"
class="flex flex-col space-y-8 mt-4">
@csrf
@method('PATCH')
<x-ui.input name="name" label="Name" :value="$profile->name" required placeholder="e.g. John Doe"/>
<x-ui.textarea :value="$broker->bio" name="bio" label="Bio" required
placeholder="Describe yourself in detail..."/>
<x-ui.input name="email" label="Email" :value="$profile->email" required
placeholder="example@email.com"/>
<x-ui.input name="phone" label="Phone" :value="$broker->phone" required placeholder="+00 00000 00000"/>
<x-ui.input name="location" label="Location" :value="$broker->location" required
placeholder="Kolkata, India"/>
<div class="grid md:grid-cols-12 w-full gap-4">
<x-ui.button variant="neutral" class="md:col-span-10">Update</x-ui.button>
<x-ui.button :link="route('broker.profile.show', $profile)"
class=" border border-accent-600/20 md:col-span-2">Cancel
</x-ui.button>
</div>
</form>
</x-dashboard.card>
</div>
</x-dashboard.broker.layout>

View File

@ -0,0 +1,71 @@
<x-dashboard.broker.layout title="Profile">
<x-slot:heading>
<x-dashboard.page-heading
title="Broker Profile"
description="Public profile information"
:back-link="route('broker.dashboard')"
>
<x-slot:end>
<x-ui.button :link="route('broker.profile.edit', auth()->user()->id)"
class="border border-accent-600/40">
<p class="hidden sm:block">Edit profile</p>
<x-heroicon-o-pencil-square class="w-4 stroke-2 sm:hidden"/>
</x-ui.button>
</x-slot:end>
</x-dashboard.page-heading>
</x-slot:heading>
<div class="flex items-center justify-center px-4 pb-4 pt-0 md:px-8 md:pb-8">
<div class="flex items-center justify-center w-full">
<x-dashboard.card class="w-full">
<div class="grid grid-cols-8 gap-6">
<div
class="col-span-8 place-self-start md:col-span-2 lg:col-span-1 flex items-center justify-center w-full">
<div
class="w-25 h-25 rounded-xl bg-linear-150 from-[#305afc] to-[#941dfb] text-5xl text-white flex justify-center items-center">
{{$initials}}
</div>
</div>
<div class="col-span-8 md:col-span-6 lg:col-span-7 flex flex-col space-y-6">
<div class="">
<p class="text-3xl font-bold">{{$name ?? 'Name'}}</p>
<div class="flex space-x-1 mt-2">
<x-ui.button-sm
variant="neutral">{{$verified ? 'Verified Broker' : 'Not Verified'}}</x-ui.button-sm>
<x-heroicon-s-star class="ml-2 w-4 fill-amber-300"/>
<p>4.8</p>
</div>
</div>
<div class="wrap-break-word">
<p>{{$bio ?? 'Bio is empty'}}</p>
</div>
<div class="grid md:grid-cols-2 md:grid-rows-2 gap-3">
<div class="fill-accent-600/70 text-accent-600/70 flex space-x-4 text-sm items-center">
<x-heroicon-o-envelope class="w-4"/>
<p>{{$email ?? 'email is empty'}}</p>
</div>
<div class="fill-accent-600/70 text-accent-600/70 flex space-x-4 text-sm items-center">
<x-heroicon-o-phone class="w-4"/>
<p>{{$phone ?? 'phone is empty'}}</p>
</div>
<div class="fill-accent-600/70 text-accent-600/70 flex space-x-4 text-sm items-center">
<x-heroicon-o-map class="w-4"/>
<p>{{$location ?? 'location is empty'}}</p>
</div>
<div class="fill-accent-600/70 text-accent-600/70 flex space-x-4 text-sm items-center">
<x-heroicon-o-arrow-trending-up class="w-4"/>
<p>Joined {{$joinDate ?? 'date is empty'}}</p>
</div>
</div>
</div>
</div>
</x-dashboard.card>
</div>
</div>
</x-dashboard.broker.layout>

View File

@ -1,6 +1,6 @@
<?php
use App\Http\Controllers\InteractionController;
use App\Http\Controllers\Interaction\InteractionController;
Route::post('/view/{deal}', [InteractionController::class, 'view'])
->middleware('throttle:30,1')

View File

@ -9,6 +9,7 @@
require __DIR__.'/web/auth.php';
require __DIR__.'/web/broker.php';
require __DIR__.'/web/interaction.php';
require __DIR__.'/web/user.php';
Route::get('/', HomeController::class)->name('home');
Route::middleware('auth')->group(function () {

View File

@ -1,7 +1,7 @@
<?php
use App\Http\Controllers\auth\AuthenticatedUserController;
use App\Http\Controllers\auth\RegisteredUserController;
use App\Http\Controllers\Auth\AuthenticatedUserController;
use App\Http\Controllers\Auth\RegisteredUserController;
Route::middleware('guest')->group(function () {
Route::resource('/login', AuthenticatedUserController::class)

12
routes/web/user.php Normal file
View File

@ -0,0 +1,12 @@
<?php
use App\Enums\UserTypes;
use App\Http\Controllers\User\UserProfileController;
use App\Http\Middleware\HasRole;
Route::prefix('/user')
->name('user.')
->middleware([HasRole::class.':'.UserTypes::User->value, 'auth'])
->group(function () {
Route::resource('profile', UserProfileController::class)->except('index', 'store', 'create');
});