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

51 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\Auth;
use App\Enums\UserStatus;
use App\Enums\UserTypes;
use App\Http\Controllers\Controller;
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.');
}
}
}