From d33e883db9131241b8c9d182cc27d9c5690eb313 Mon Sep 17 00:00:00 2001 From: stevan Date: Wed, 10 Sep 2025 10:54:38 +0200 Subject: [PATCH] Allow update city by active countries --- app/Http/Controllers/UserController.php | 1 + app/Providers/AppServiceProvider.php | 13 +++++++- public/js/ext/functions.js | 41 +++++++++++++++++++++++++ resources/views/profile.blade.php | 21 +++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 497e64e03..8d2c70315 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -24,6 +24,7 @@ public function update() 'privacy' => 'required', 'receive_emails' => 'required', 'country_iso' => 'nullable|exists:countries,iso', + 'city_id' => 'nullable|exists:cities,id', 'twitter' => 'nullable', 'website' => 'nullable', 'bio' => 'nullable', diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 07d9637ad..6aacdd9d1 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -49,12 +49,23 @@ function ($view) { return $theme; }); + $activeCountries = \App\Country::withEvents(); + $view->with('audiences', $audiences); $view->with('activity_types', \App\ActivityType::list()); $view->with('countries', \App\Country::translated()); $view->with('languages', Arr::sort(Lang::get('base.languages'))); - $view->with('active_countries', \App\Country::withEvents()); + $view->with('active_countries', $activeCountries); $view->with('themes', $themes); + + $cities = \App\City::query() + ->whereIn('country_iso', $activeCountries->pluck('iso')) + ->select(['id', 'city', 'country_iso']) + ->orderBy('country_iso') + ->orderBy('city') + ->get(); + + $view->with('cities', $cities); } ); diff --git a/public/js/ext/functions.js b/public/js/ext/functions.js index 67b418824..544110fd6 100755 --- a/public/js/ext/functions.js +++ b/public/js/ext/functions.js @@ -2131,6 +2131,46 @@ var SEMICOLON = SEMICOLON || {}; } }, + cityFilter: function () { + var $country = $('#id_country'); + var $city = $('#id_city'); + if (!$country.length || !$city.length) return; + + // cache once per current DOM + if (!$city.data('originalOptions')) { + $city.data('originalOptions', $city.find('option').clone()); + $city.data('emptyOption', $city.find('option').first().clone()); + } + + function applyCityFilter() { + var iso = $country.val() || ''; + var prev = $city.val(); + var $original = $city.data('originalOptions'); + var $empty = $city.data('emptyOption').clone(); + + var $next = [$empty.get(0)]; + if (iso) { + $original.each(function (i, opt) { + if (i === 0) return; // keep first for empty + var $opt = $(opt); + if ($opt.attr('data-country') === iso) $next.push(opt); + }); + } + $city.empty().append($next); + + // restore previous if still valid + if ($next.some(function(o){ return o.value === prev; })) { + $city.val(prev); + } else { + $city.val(''); + } + } + + // bind once per render + $country.off('change.cityfilter').on('change.cityfilter', applyCityFilter); + applyCityFilter(); + }, + masonryThumbs: function(){ var $masonryThumbsEl = $('.masonry-thumbs'); if( $masonryThumbsEl.length > 0 ){ @@ -2574,6 +2614,7 @@ var SEMICOLON = SEMICOLON || {}; SEMICOLON.slider.owlCaptionInit(); SEMICOLON.header.topsocial(); SEMICOLON.header.responsiveMenuClass(); + SEMICOLON.widget.cityFilter(); } }; diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php index 72f879ab2..666f9f6ad 100755 --- a/resources/views/profile.blade.php +++ b/resources/views/profile.blade.php @@ -175,6 +175,27 @@ class="border-2 border-solid border-dark-blue-200 w-full rounded-full h-12 px-4 +
+
+ + +
+
+ @component('components.validation-errors', ['field'=>'city_id'])@endcomponent +
+
+