Skip to content

Commit

Permalink
Add: New migration for Laravel Wilayah; Update: README, Model relatio…
Browse files Browse the repository at this point in the history
…nships.

-    Added new migration file for creating laravel wilayah tables using the configuration file for table prefixing.
-    Updated README.md with new example usage for API configuration and response columns.
-    Changed the command for running the tests in README.md.
-    Added Laravel 9 tests to the GitHub actions workflows.
-    Modified models to define database relationships properly.
-    Improved formatting in several migration and model files.
-    Renamed and updated tests from ExampleTest to ModelTest.
  • Loading branch information
hanzo-asashi committed Oct 8, 2023
1 parent 87e5990 commit c8259ab
Show file tree
Hide file tree
Showing 21 changed files with 542 additions and 159 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/run-tests.yml
Expand Up @@ -20,8 +20,16 @@ jobs:
- laravel: 10.*
testbench: 8.*
carbon: ^2.63
- laravel: 9.*
php: 8.1
testbench: ^7.0
stability: prefer-stable
- laravel: 9.*
php: 8.1
testbench: ^7.0
stability: prefer-lowest

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: Laravel ${{ matrix.laravel }} with PHP ${{ matrix.php }} - ${{ matrix.stability }} on ${{ matrix.os }}

steps:
- name: Checkout code
Expand All @@ -31,7 +39,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd,exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
Expand Down
48 changes: 47 additions & 1 deletion README.md
Expand Up @@ -40,6 +40,52 @@ This is the contents of the published config file:

```php
return [
'table_prefix' => 'ind_',

/**
* API Configuration.
*/
'api' => [
/**
* If enabled, this will load Indonesia API.
* - http://localhost:8000/api/wilayah/provinces
* - http://localhost:8000/api/wilayah/cities
* - http://localhost:8000/api/wilayah/districts
* - http://localhost:8000/api/wilayah/villages
*/
'enabled' => true,

/**
* The middleware for Indonesia API.
*/
'middleware' => ['api'],

/**
* The route name for Indonesia API.
*/
'route_name' => 'api.wilayah',

/**
* The route prefix for Indonesia API.
*/
'route_prefix' => 'api/wilayah',

/**
* Specify which column will be displayed in the response data.
* Only support columns from database.
*/
'response_columns' => [
//.
'province' => ['code', 'name'],

'city' => ['city_code', 'province_code', 'name'],

'district' => ['district_code', 'city_code', 'name'],

'village' => ['village_code', 'district_code', 'name'],

'island' => ['province_code', 'city_code', 'island_code', 'name'],
],
];
```

Expand All @@ -59,7 +105,7 @@ echo $laravelWilayah->echoPhrase('Hello, HanzoAlpha!');
## Testing

```bash
composer test
./vendor/bin/pest
```

## Changelog
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Expand Up @@ -2,9 +2,10 @@
"name": "hanzoalpha/laravel-wilayah",
"description": "Laravel Package For Wilayah Indonesia",
"keywords": [
"hanzoalpha",
"wilayah",
"laravel",
"laravel-wilayah"
"indonesia",
"administrative"
],
"homepage": "https://github.com/hanzoalpha/laravel-wilayah",
"license": "MIT",
Expand All @@ -16,7 +17,7 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.1|^8.2",
"spatie/laravel-package-tools": "^1.14.0",
"laravel/framework": "^9.0|^10.0",
"staudenmeir/eloquent-has-many-deep": "^1.11",
Expand All @@ -27,7 +28,7 @@
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.8",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.8",
"orchestra/testbench": "^7.0|^8.8",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-arch": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
Expand Down Expand Up @@ -61,8 +62,8 @@
"@php vendor/bin/testbench serve"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"test": "vendor/bin/pest --stop-on-failure",
"test-coverage": "XDEBUG_MODE=coverage vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion config/wilayah.php
Expand Up @@ -7,7 +7,7 @@
/**
* Table prefix for wilayah tables: provinces, cities, districts and villages.
*/
'table_prefix' => 'ind_',
'table_prefix' => 'wilayah_',

/**
* API Configuration.
Expand Down
Binary file added database.sqlite
Binary file not shown.
2 changes: 0 additions & 2 deletions database/factories/ModelFactory.php
Expand Up @@ -2,8 +2,6 @@

namespace HanzoAlpha\LaravelWilayah\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/*
class ModelFactory extends Factory
{
Expand Down
21 changes: 10 additions & 11 deletions database/migrations/2023_10_05_030904_create_wilayah_table.php
Expand Up @@ -6,56 +6,55 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
public function up(): void
{
Schema::create(config('wilayah.table_prefix').'cities', static function (Blueprint $table) {
Schema::create(config('wilayah.table_prefix') . 'cities', static function (Blueprint $table) {
$table->char('city_code', 4)->primary();
$table->char('province_code', 2);
$table->string('name', 255);
$table->foreign('province_code')
->references('province_code')
->on(config('wilayah.table_prefix').'provinces')
->on(config('wilayah.table_prefix') . 'provinces')
->onUpdate('cascade')
->onDelete('restrict');
});

Schema::create(config('wilayah.table_prefix').'districts', static function (Blueprint $table) {
Schema::create(config('wilayah.table_prefix') . 'districts', static function (Blueprint $table) {
$table->char('district_code', 7)->primary();
$table->char('city_code', 4);
$table->string('name', 255);
$table->foreign('city_code')
->references('city_code')
->on(config('wilayah.table_prefix').'cities')
->on(config('wilayah.table_prefix') . 'cities')
->onUpdate('cascade')
->onDelete('restrict');
});

Schema::create(config('wilayah.table_prefix').'villages', static function (Blueprint $table) {
Schema::create(config('wilayah.table_prefix') . 'villages', static function (Blueprint $table) {
$table->char('village_code', 10)->primary();
$table->char('district_code', 7);
$table->string('name', 255);
$table->foreign('district_code')
->references('district_code')
->on(config('wilayah.table_prefix').'districts')
->on(config('wilayah.table_prefix') . 'districts')
->onUpdate('cascade')
->onDelete('restrict');
});

Schema::create(config('wilayah.table_prefix').'islands', static function (Blueprint $table) {
Schema::create(config('wilayah.table_prefix') . 'islands', static function (Blueprint $table) {
$table->char('island_code', 5)->primary();
$table->char('province_code', 2);
$table->char('city_code', 4);
$table->string('name', 255);
$table->foreign('province_code')
->references('province_code')
->on(config('wilayah.table_prefix').'provinces')
->on(config('wilayah.table_prefix') . 'provinces')
->onUpdate('cascade')
->onDelete('restrict');
$table->foreign('city_code')
->references('city_code')
->on(config('wilayah.table_prefix').'cities')
->on(config('wilayah.table_prefix') . 'cities')
->onUpdate('cascade')
->onDelete('restrict');
});
Expand Down
63 changes: 63 additions & 0 deletions database/migrations/create_laravel_wilayah_table.php.stub
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create(config('wilayah.table_prefix').'cities', static function (Blueprint $table) {
$table->char('city_code', 4)->primary();
$table->char('province_code', 2);
$table->string('name', 255);
$table->foreign('province_code')
->references('province_code')
->on(config('wilayah.table_prefix').'provinces')
->onUpdate('cascade')
->onDelete('restrict');
});

Schema::create(config('wilayah.table_prefix').'districts', static function (Blueprint $table) {
$table->char('district_code', 7)->primary();
$table->char('city_code', 4);
$table->string('name', 255);
$table->foreign('city_code')
->references('city_code')
->on(config('wilayah.table_prefix').'cities')
->onUpdate('cascade')
->onDelete('restrict');
});

Schema::create(config('wilayah.table_prefix').'villages', static function (Blueprint $table) {
$table->char('village_code', 10)->primary();
$table->char('district_code', 7);
$table->string('name', 255);
$table->foreign('district_code')
->references('district_code')
->on(config('wilayah.table_prefix').'districts')
->onUpdate('cascade')
->onDelete('restrict');
});

Schema::create(config('wilayah.table_prefix').'islands', static function (Blueprint $table) {
$table->char('island_code', 5)->primary();
$table->char('province_code', 2);
$table->char('city_code', 4);
$table->string('name', 255);
$table->foreign('province_code')
->references('province_code')
->on(config('wilayah.table_prefix').'provinces')
->onUpdate('cascade')
->onDelete('restrict');
$table->foreign('city_code')
->references('city_code')
->on(config('wilayah.table_prefix').'cities')
->onUpdate('cascade')
->onDelete('restrict');
});
}
};
19 changes: 0 additions & 19 deletions database/migrations/create_wilayah_table.php.stub

This file was deleted.

14 changes: 14 additions & 0 deletions pint.json
@@ -0,0 +1,14 @@
{
"preset": "laravel",
"rules": {
"blank_line_before_statement": true,
"concat_space": {
"spacing": "one"
},
"method_argument_space": true,
"single_trait_insert_per_statement": true,
"types_spaces": {
"space": "single"
}
}
}

0 comments on commit c8259ab

Please sign in to comment.