interim fix for drop downs

This commit is contained in:
Mark Gregory
2026-07-07 11:57:02 +01:00
parent fd63173736
commit 9cc2ce530e
9 changed files with 520 additions and 323 deletions
@@ -13,10 +13,7 @@ use Modules\Countries\Support\CountryUsageReport;
class CountriesController extends Controller
{
/**
* Display ISO 3166 country records.
*/
public function index(Request $request): View
public function __invoke(Request $request): View
{
$search = trim((string) $request->query('search', ''));
$status = (string) $request->query('status', 'all');
@@ -40,80 +37,78 @@ class CountriesController extends Controller
->when($status === 'active', fn ($query) => $query->where('is_active', true))
->when($status === 'inactive', fn ($query) => $query->where('is_active', false))
->when($region !== 'all' && $region !== '', fn ($query) => $query->where('region', $region))
->ordered()
->orderByRaw('LOWER(COALESCE(display_name, common_name, name)) ASC')
->paginate(50)
->withQueryString();
$activeCount = Country::query()->where('is_active', true)->count();
$inactiveCount = Country::query()->where('is_active', false)->count();
$totalCount = Country::query()->count();
$regions = Country::query()->whereNotNull('region')->distinct()->orderBy('region')->pluck('region');
return view('countries::index', compact('countries', 'activeCount', 'inactiveCount', 'totalCount', 'search', 'status', 'region', 'regions'));
$regions = Country::query()
->whereNotNull('region')
->distinct()
->orderBy('region')
->pluck('region');
return view('countries::index', compact(
'countries',
'activeCount',
'inactiveCount',
'totalCount',
'search',
'status',
'region',
'regions'
));
}
/**
* Show the country creation form.
*/
public function create(): View
{
return view('countries::create', ['country' => new Country]);
}
/**
* Store a new ISO country record.
*/
public function store(StoreCountryRequest $request): RedirectResponse
{
$country = Country::query()->create($this->payload($request));
return redirect()->route('countries.show', $country)->with('success', 'Country created.');
return redirect()
->route('countries.show', $country)
->with('success', 'Country created.');
}
/**
* Show a country record.
*/
public function show(Country $country, CountryUsageReport $usageReport): View
{
$country->load(['subdivisions' => fn ($query) => $query->ordered()->limit(250)]);
$usageRows = $usageReport->forCountry($country);
return view('countries::show', compact('country', 'usageRows'));
}
/**
* Show the edit form.
*/
public function edit(Country $country): View
{
return view('countries::edit', compact('country'));
}
/**
* Update all editable ISO/support fields.
*/
public function update(UpdateCountryRequest $request, Country $country): RedirectResponse
{
$country->update($this->payload($request));
return redirect()->route('countries.show', $country)->with('success', 'Country updated.');
return redirect()
->route('countries.show', $country)
->with('success', 'Country updated.');
}
/**
* Soft-delete a custom/retired country record.
*/
public function destroy(Country $country): RedirectResponse
{
$country->delete();
return redirect()->route('countries.index')->with('success', 'Country archived.');
return redirect()
->route('countries.index')
->with('success', 'Country archived.');
}
/**
* Build the database payload from validated request data.
*
* @return array<string, mixed>
*/
private function payload(StoreCountryRequest|UpdateCountryRequest $request): array
{
$data = $request->validated();
@@ -130,7 +125,10 @@ class CountriesController extends Controller
foreach (['languages', 'timezones', 'metadata'] as $jsonField) {
$value = $data[$jsonField] ?? null;
$data[$jsonField] = blank($value) ? null : json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
$data[$jsonField] = blank($value)
? null
: json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
}
foreach (['is_active', 'independent', 'un_member'] as $booleanField) {