From 92a2f70b1508595d403c78718edee4d6ac24f183 Mon Sep 17 00:00:00 2001 From: raccoon254 Date: Fri, 14 Jun 2024 11:56:58 +0300 Subject: [PATCH] Revert back register to MVC route --- .../Auth/RegisteredUserController.php | 7 ++++ app/Livewire/Register.php | 22 ++++++++++--- resources/views/auth/register.blade.php | 32 +++++-------------- routes/auth.php | 2 +- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index cace061..7a3673b 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -18,6 +18,13 @@ class RegisteredUserController extends Controller { + /** + * Display the registration view. + */ + public function create(): View + { + return view('auth.register'); + } /** * Handle an incoming registration request. * diff --git a/app/Livewire/Register.php b/app/Livewire/Register.php index 75970c3..c57241d 100644 --- a/app/Livewire/Register.php +++ b/app/Livewire/Register.php @@ -12,14 +12,13 @@ use Illuminate\Foundation\Application; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Redirector; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Notification; use Illuminate\View\View; -use Livewire\Attributes\Validate; use Livewire\Component; class Register extends Component { - public $name; public $email; public $phone; @@ -27,9 +26,24 @@ class Register extends Component public $password; public $password_confirmation; - public function register(): Application|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse + public function mount(): void { + $this->location = $this->getUserCountry(); + } + public function getUserCountry(): string + { + try { + $response = Http::get('https://ipinfo.io/json'); + $data = $response->json(); + return $data['country'] ?? 'Unknown'; + } catch (\Exception $e) { + return 'Unknown'; + } + } + + public function register(): Application|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse + { $user_data_array = [ 'name' => $this->name, 'email' => $this->email, @@ -38,8 +52,6 @@ public function register(): Application|Redirector|\Illuminate\Contracts\Foundat 'password' => Hash::make($this->password), ]; - dd($user_data_array); - $this->validate([ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class], diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 644e454..5e50003 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -1,7 +1,6 @@ -
+
@csrf -
@@ -14,14 +13,14 @@
-
- +
+
-
+
@@ -71,28 +70,15 @@
- @script - @endscript -
+ diff --git a/routes/auth.php b/routes/auth.php index f8e92bb..d2a7f6a 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Route; Route::middleware('guest')->group(function () { - Route::get('register', Register::class) + Route::get('register', [RegisteredUserController::class, 'create']) ->name('register'); Route::post('register', [RegisteredUserController::class, 'store']);