Skip to content

Commit

Permalink
Adaptation of the Mopux Locations to Linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pardalsalcap committed Nov 22, 2023
1 parent 15a5c9c commit 3d011a4
Show file tree
Hide file tree
Showing 55 changed files with 2,780 additions and 179 deletions.
56 changes: 20 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# Add on to Linter to manage Geolocations

[![Latest Version on Packagist](https://img.shields.io/packagist/v/pardalsalcap/linter-locations.svg?style=flat-square)](https://packagist.org/packages/pardalsalcap/linter-locations)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/pardalsalcap/linter-locations/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/pardalsalcap/linter-locations/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/pardalsalcap/linter-locations/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/pardalsalcap/linter-locations/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/pardalsalcap/linter-locations.svg?style=flat-square)](https://packagist.org/packages/pardalsalcap/linter-locations)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/linter-locations.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/linter-locations)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

Expand All @@ -40,39 +30,31 @@ This is the contents of the published config file:

```php
return [
'available_locales' => [
'ca' => 'Català',
'es' => 'Castellano',
'en' => 'English',
],
];
```

Optionally, you can publish the views using

```bash
php artisan vendor:publish --tag="linter-locations-views"
```

## Usage
You can add a relationship to the User model

```php
$linterLocations = new Pardalsalcap\LinterLocations();
echo $linterLocations->echoPhrase('Hello, Pardalsalcap!');
```

## Testing

```bash
composer test
use Pardalsalcap\LinterLocations\Models\Address;

public function addresses(): BelongsToMany
{
return $this->belongsToMany(
Address::class, // Address model
'address_user', // Pivot table name
'user_id', // Foreign key on the pivot table for the User model
'address_id' // Foreign key on the pivot table for the Address model
)->withPivot('address_type');
}
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security Vulnerabilities

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
Explain how to extend with service provider

## Credits

Expand All @@ -82,3 +64,5 @@ Please review [our security policy](../../security/policy) on how to report secu
## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.


2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^8.1",
"pardalsalcap/linter": "dev-develop",
"filament/filament": "^3.0-stable",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.14.0"
},
Expand Down
7 changes: 6 additions & 1 deletion config/linter-locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

// config for Pardalsalcap/LinterLocations
return [

'available_locales' => [
'ca' => 'Català',
'es' => 'Castellano',
'en' => 'English',
],
'use_scoped_search' => true,
];
115 changes: 0 additions & 115 deletions database/migrations/create_linter_locations_table.php.stub

This file was deleted.

148 changes: 148 additions & 0 deletions database/migrations/create_linter_locations_tables.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

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

return new class extends Migration {
public function up()
{
Schema::create('continents', function (Blueprint $table) {
$table->id();
$table->decimal('lat', 11, 7)->nullable()->comment('Latitude');
$table->decimal('lon', 11, 7)->nullable()->comment('Longitude');
$table->string('iso', 2)->unique()->nullable()->comment('ISO code');
$table->string('name')->index()->comment('Continent Name');
$table->json('translations')->nullable()->comment('Name Translations');
$table->timestamps();
});

Schema::create('countries', function (Blueprint $table) {
$table->id();
$table->bigInteger('continent_id')->nullable()->unsigned();
$table->decimal('lat', 11, 7)->nullable()->comment('Latitude');
$table->decimal('lon', 11, 7)->nullable()->comment('Longitude');
$table->string('iso', 2)->unique()->nullable()->comment('ISO 2-letter code');
$table->string('iso3', 3)->unique()->nullable()->comment('ISO 3-letter code');
$table->string('name')->index()->comment('Country Name');
$table->json('translations')->nullable()->comment('Name Translations');
$table->timestamps();

$table->foreign('continent_id')
->references('id')->on('continents')
->onDelete('set null')
->onUpdate('cascade');
});

Schema::create('communities', function (Blueprint $table) {
$table->id();
$table->bigInteger('country_id')->nullable()->unsigned()->comment('Country ID');
$table->decimal('lat', 11, 7)->nullable()->comment('Latitude');
$table->decimal('lon', 11, 7)->nullable()->comment('Longitude');
$table->string('iso', 2)->nullable()->comment('ISO Code');
$table->string('name')->index()->comment('Community Name');
$table->json('translations')->nullable()->comment('Name Translations');
$table->timestamps();

// Foreign key reference
$table->foreign('country_id')
->references('id')->on('countries')
->onDelete('set null')
->onUpdate('cascade');

// Composite unique index for country_id and iso
$table->unique(['country_id', 'iso'], 'country_iso_unique');
});

Schema::create('states', function (Blueprint $table) {
$table->id();
$table->bigInteger('country_id')->nullable()->unsigned()->comment('Country ID');
$table->bigInteger('community_id')->nullable()->unsigned()->comment('Community ID');
$table->decimal('lat', 11, 7)->nullable()->comment('Latitude');
$table->decimal('lon', 11, 7)->nullable()->comment('Longitude');
$table->string('iso', 2)->nullable()->comment('ISO Code');
$table->string('name')->index()->comment('State Name');
$table->json('translations')->nullable()->comment('Name Translations');
$table->timestamps();

// Foreign key references
$table->foreign('country_id')
->references('id')->on('countries')
->onDelete('set null')
->onUpdate('cascade');
$table->foreign('community_id')
->references('id')->on('communities')
->onDelete('set null')
->onUpdate('cascade');

// Composite unique index for country_id and iso
$table->unique(['country_id', 'iso'], 'state_country_iso_unique');
});

Schema::create('cities', function (Blueprint $table) {
$table->id();
$table->bigInteger('state_id')->nullable()->unsigned()->comment('State ID');
$table->decimal('lat', 11, 7)->nullable()->comment('Latitude');
$table->decimal('lon', 11, 7)->nullable()->comment('Longitude');
$table->string('po', 10)->nullable()->comment('Postal Code'); // Adjusted length
$table->string('name')->index()->comment('City Name');
$table->json('translations')->nullable()->comment('Name Translations');
$table->timestamps();

// Foreign key reference
$table->foreign('state_id')
->references('id')->on('states')
->onDelete('set null')
->onUpdate('cascade');

// Optional: Composite unique index for state_id and po
$table->unique(['state_id', 'po'], 'state_po_unique');
});

Schema::create('addresses', function (Blueprint $table) {
$table->id();
$table->bigInteger('city_id')->nullable()->unsigned()->comment('City ID');
$table->decimal('lat', 11, 7)->nullable()->comment('Latitude');
$table->decimal('lon', 11, 7)->nullable()->comment('Longitude');
$table->string('po', 10)->nullable()->comment('Postal Code');
$table->string('address', 100)->nullable()->comment('Address Line');
$table->string('number', 10)->nullable()->comment('Building/Property Number');
$table->string('stair', 25)->nullable()->comment('Stair');
$table->string('floor', 10)->nullable()->comment('Floor');
$table->string('door', 10)->nullable()->comment('Door');
$table->timestamps();

// Foreign key reference
$table->foreign('city_id')
->references('id')->on('cities')
->onDelete('set null')
->onUpdate('cascade');
$table->unique(['city_id', 'address', 'number', 'stair', 'floor', 'door'], 'address_unique');
});

Schema::create('addressables', function (Blueprint $table) {
$table->bigInteger('address_id')->unsigned();
$table->bigInteger('addressable_id')->unsigned();
$table->string('addressable_type');
$table->string('address_type')->nullable();
$table->foreign('address_id')->references('id')->on('addresses')->cascadeOnUpdate()->cascadeOnDelete();
});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('addressables');
Schema::dropIfExists('addresses');
Schema::dropIfExists('cities');
Schema::dropIfExists('states');
Schema::dropIfExists('communities');
Schema::dropIfExists('countries');
Schema::dropIfExists('continents');
}
};
Loading

0 comments on commit 3d011a4

Please sign in to comment.