dealhub/app/Http/Controllers/RegisteredUserController.php
kusowl ccb5a2ed5e refactor: consolidate alert components and improve functionality
- replaced `alert-error` and `alert-success` components with a single reusable `alert` component
- added JS functionality for dismissible alerts
- updated related views to use the new `alert` component
- adjusted broker profile logic to display initials and verification status dynamically
- refactored morph relations from `type` to `role`
- enhanced image preview behavior for file inputs
- made broker migration fields nullable and added safeguards against registration errors
- Added confirmation when a user wants delete deal
- Add dynamic initials for user profile picture
- make image file name non-overidding with timestamp
2026-01-14 12:19:20 +05:30

51 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Enums\UserStatus;
use App\Enums\UserTypes;
use App\Http\Requests\StoreRegisterdUser;
use App\Models\Broker;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class RegisteredUserController extends Controller
{
public function create()
{
return view('auth.register');
}
public function store(StoreRegisterdUser $request)
{
$data = $request->validated();
try {
DB::transaction(function () use ($data) {
if ($data['role'] === UserTypes::Broker->value) {
$data['status'] = UserStatus::Pending->value;
// Create Broker first, then the User linked to it
$broker = Broker::create();
$broker->user()->create($data);
} else {
$data['status'] = UserStatus::Active->value;
User::create($data);
}
});
return to_route('login.create')
->with('userRegistered', 'User registered successfully.');
} catch (\Throwable $e) {
Log::error('Registration Failed: '.$e->getMessage());
return back()
->withInput()
->with('error', 'Something went wrong during registration.');
}
}
}