From 919fd918d6e061d4a27302beada8675e6d2253cc Mon Sep 17 00:00:00 2001 From: raccoon254 Date: Fri, 14 Jun 2024 11:34:37 +0300 Subject: [PATCH] Created script update for the location --- app/Livewire/Register.php | 18 ++++++---- resources/views/auth/register.blade.php | 48 ++++++++++++++----------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/app/Livewire/Register.php b/app/Livewire/Register.php index 7b620be..75970c3 100644 --- a/app/Livewire/Register.php +++ b/app/Livewire/Register.php @@ -5,6 +5,7 @@ use App\Models\User; use App\Notifications\NewUserJoined; use App\Notifications\UserWelcome; +use Illuminate\Auth\Events\Registered; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\Rules; @@ -19,21 +20,26 @@ class Register extends Component { - #[Validate('required', 'string', 'max:255', 'min:3')] public $name; - #[Validate('required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class)] public $email; - #[Validate('required', 'string', 'max:255', 'min:8', 'unique:' . User::class)] public $phone; - #[Validate('required', 'string', 'max:255', 'min:3')] public $location; - #[Validate('required', 'confirmed')] public $password; - #[Validate('required')] public $password_confirmation; public function register(): Application|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse { + + $user_data_array = [ + 'name' => $this->name, + 'email' => $this->email, + 'phone' => $this->phone, + 'location' => $this->location, + '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 16cdf8b..de3cd62 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -5,36 +5,36 @@
- @error('name') @enderror
-
- -
- - - @error('phone') - @enderror -
+
+
+ +
+ + +
- -
- - - @error('location') - @enderror + +
+ + +
+ @error('phone') @enderror + @error('location') @enderror
- @error('email') @enderror @@ -43,7 +43,7 @@
- @error('password') @enderror @@ -53,7 +53,7 @@
+ wire:model="password_confirmation" required autocomplete="new-password"/> @error('password_confirmation') @enderror
@@ -77,6 +77,14 @@ let phoneInput = window.intlTelInput(phoneInputField, { utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js", }); + + // When we select a country, update the location field + phoneInputField.addEventListener("countrychange", function () { + let countryData = phoneInput.getSelectedCountryData(); + document.querySelector("#location").value = countryData.name; + // update wire location + @this.set('location', countryData.name); + }); @endscript