added countries support expanded for ISO 3166 standard merged in new support

This commit is contained in:
Mark Gregory
2026-06-15 10:16:57 +01:00
parent 8a6eb74ebb
commit 6acc6de707
7 changed files with 126 additions and 30 deletions
@@ -10,13 +10,20 @@ use Modules\Countries\Support\ModuleInfo;
class CountriesServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Countries';
protected string $moduleNameLower = 'countries';
/**
* Register module services.
*/
public function register(): void
{
$this->app->register(RouteServiceProvider::class);
}
/**
* Bootstrap module services.
*/
public function boot(): void
{
$this->registerTranslations();
@@ -24,72 +31,127 @@ class CountriesServiceProvider extends ServiceProvider
$this->registerViews();
$this->registerHelpers();
$this->registerCommands();
$this->loadMigrationsFrom(module_path(ModuleInfo::name(), 'Database/Migrations'));
$this->registerMigrations();
}
public function provides(): array
/**
* Register module migrations using the real filesystem path.
*/
protected function registerMigrations(): void
{
return [];
$path = dirname(__DIR__).'/Database/Migrations';
if (is_dir($path)) {
$this->loadMigrationsFrom($path);
}
}
/**
* Register module helper files.
*/
protected function registerHelpers(): void
{
foreach (glob(__DIR__.'/../Helpers/*.php') ?: [] as $filename) {
foreach (glob(dirname(__DIR__).'/Helpers/*.php') ?: [] as $filename) {
require_once $filename;
}
}
/**
* Register console commands when present.
*/
protected function registerCommands(): void
{
if (! $this->app->runningInConsole()) {
return;
}
$commandPath = __DIR__.'/../Console';
$commandPath = dirname(__DIR__).'/Console';
if (! is_dir($commandPath)) {
return;
}
$commands = collect(File::allFiles($commandPath))
->map(fn ($file): string => 'Modules\\'.$this->moduleName.'\\Console\\'.$file->getFilenameWithoutExtension())
->filter(fn (string $class): bool => class_exists($class))
->values()
->all();
$this->commands($commands);
if ($commands !== []) {
$this->commands($commands);
}
}
/**
* Register module config.
*/
protected function registerConfig(): void
{
$sourcePath = dirname(__DIR__).'/Config/config.php';
if (! is_file($sourcePath)) {
return;
}
$this->publishes([
module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower().'.php'),
$sourcePath => config_path(ModuleInfo::nameLower().'.php'),
], 'config');
$this->mergeConfigFrom(module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower());
$this->mergeConfigFrom($sourcePath, ModuleInfo::nameLower());
}
/**
* Register module views.
*/
protected function registerViews(): void
{
$viewPath = resource_path('views/modules/'.ModuleInfo::nameLower());
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', ModuleInfo::nameLower().'-module-views']);
$sourcePath = dirname(__DIR__).'/Resources/views';
if (! is_dir($sourcePath)) {
return;
}
$this->publishes([
$sourcePath => $viewPath,
], ['views', ModuleInfo::nameLower().'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
}
/**
* Register module translations.
*/
protected function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.ModuleInfo::nameLower());
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
$publishedPath = resource_path('lang/modules/'.ModuleInfo::nameLower());
$sourcePath = dirname(__DIR__).'/Resources/lang';
if (is_dir($publishedPath)) {
$this->loadTranslationsFrom($publishedPath, ModuleInfo::nameLower());
return;
}
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower());
if (is_dir($sourcePath)) {
$this->loadTranslationsFrom($sourcePath, ModuleInfo::nameLower());
}
}
/**
* Get published view paths.
*
* @return array<int, string>
*/
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (Config::get('view.paths') as $path) {
foreach (Config::get('view.paths', []) as $path) {
if (is_dir($path.'/modules/'.ModuleInfo::nameLower())) {
$paths[] = $path.'/modules/'.ModuleInfo::nameLower();
}
}
return $paths;
}
}
@@ -7,19 +7,36 @@ use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* Register Countries module routes.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapApiRoutes();
}
/**
* Register web routes from the real module path.
*/
protected function mapWebRoutes(): void
{
Route::middleware(['web', 'auth'])->group(module_path('Countries', 'Routes/web.php'));
$path = dirname(__DIR__).'/Routes/web.php';
if (is_file($path)) {
Route::middleware(['web', 'auth'])->group($path);
}
}
/**
* Register API routes from the real module path.
*/
protected function mapApiRoutes(): void
{
Route::prefix('api/v1')->middleware(['api', 'auth:sanctum'])->group(module_path('Countries', 'Routes/api.php'));
$path = dirname(__DIR__).'/Routes/api.php';
if (is_file($path)) {
Route::middleware(['api'])->group($path);
}
}
}
+7 -3
View File
@@ -3,10 +3,14 @@
use Illuminate\Support\Facades\Route;
use Modules\Countries\Http\Controllers\Api\CountriesApiController;
Route::middleware(['api'])->prefix('api/countries')->name('api.countries.')->group(function (): void {
Route::prefix('api/v1/countries')->name('api.countries.')->group(function (): void {
Route::get('/', [CountriesApiController::class, 'index'])->name('index');
Route::get('/active', [CountriesApiController::class, 'active'])->name('active');
Route::get('/resolve/{code}', [CountriesApiController::class, 'resolve'])->where('code', '[A-Za-z0-9]{2,3}')->name('resolve');
Route::get('/resolve/{code}', [CountriesApiController::class, 'resolve'])
->where('code', '[A-Za-z0-9]{2,3}')
->name('resolve');
Route::get('/{country:alpha2}', [CountriesApiController::class, 'show'])->name('show');
Route::get('/{alpha2}/subdivisions', [CountriesApiController::class, 'subdivisions'])->where('alpha2', '[A-Za-z]{2}')->name('subdivisions');
Route::get('/{alpha2}/subdivisions', [CountriesApiController::class, 'subdivisions'])
->where('alpha2', '[A-Za-z]{2}')
->name('subdivisions');
});
+3
View File
@@ -5,7 +5,10 @@ use Modules\Countries\Http\Controllers\CountriesController;
Route::prefix('countries')->name('countries.')->middleware(['web', 'auth'])->group(function (): void {
Route::get('/', [CountriesController::class, 'index'])->name('index');
Route::get('/create', [CountriesController::class, 'create'])->name('create');
Route::post('/', [CountriesController::class, 'store'])->name('store');
Route::get('/{country:alpha2}', [CountriesController::class, 'show'])->name('show');
Route::get('/{country:alpha2}/edit', [CountriesController::class, 'edit'])->name('edit');
Route::put('/{country:alpha2}', [CountriesController::class, 'update'])->name('update');
Route::delete('/{country:alpha2}', [CountriesController::class, 'destroy'])->name('destroy');
});
@@ -0,0 +1,18 @@
<?php
namespace Modules\Countries\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class ValidCountryCode implements ValidationRule
{
public function __construct(private readonly bool $activeOnly = true)
{
}
public function validate(string $attribute, mixed $value, Closure $fail): void
{
(new ValidIso3166CountryCode($this->activeOnly, 'alpha2'))->validate($attribute, $value, $fail);
}
}
-8
View File
@@ -1,12 +1,4 @@
versions:
- version: 1.3.0
date: 2026-06-15
changes:
- Exposed all ISO 3166 country parameters in create and edit CRUD forms.
- Added create, store and destroy actions for platform country administration.
- Added professional WMS-styled form layout with red required-field indicators.
- Added editable metadata JSON, source tracking, sync timestamp and operational support flags.
- Updated country index and show views to display full ISO and operational metadata.
- version: 1.2.0
date: 2026-06-15
changes:
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "Countries",
"alias": "countries",
"version": "1.3.0",
"version": "1.2.0",
"description": "ISO 3166 country reference module with active-country support for WMS and SaaS workflows.",
"keywords": [
"countries",