Skip to content

Commit

Permalink
feature: add API enable/disable configuration for Algerian Cities pac…
Browse files Browse the repository at this point in the history
…kage
  • Loading branch information
n4ss1m committed Oct 30, 2024
1 parent c994d89 commit 4993f75
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ It provides functionality to load Wilayas (provinces) and Communes (municipaliti
- Wilaya and Commune Eloquent models with relationships.
- Supports Arabic and French languages.
- Includes postal codes and latitude/longitude for each commune.
- Available as API endpoints.
- Helper functions for easy integration in Blade views.
- [Helper functions for easy integration in Blade views](#using-helper-functions).
- [Available as API endpoints](#using-the-package-as-an-api).

## Requirements

Expand Down Expand Up @@ -51,23 +51,14 @@ The package provides two models: `Wilaya` and `Commune`.
A `Wilaya` has many `Commune`, and you can interact with them just like any other Eloquent models.

```php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Kossa\AlgerianCities\Commune;
use Kossa\AlgerianCities\Wilaya;

class AnyClass extends Model
{
// Retrieve all Wilayas
$wilayas = Wilaya::all();

// Retrieve all Communes
$communes = Commune::all();

// Get all Communes belonging to Algiers (Wilaya ID: 16)
$algiers_communes = Commune::where('wilaya_id', 16)->get();
}
// Retrieve all Wilayas
$wilayas = Wilaya::all();

// Retrieve all Communes
$communes = Commune::all();

// Get all Communes belonging to Algiers (Wilaya ID: 16)
$algiers_communes = Commune::where('wilaya_id', 16)->get();
```

### Using Helper Functions
Expand Down Expand Up @@ -143,6 +134,16 @@ This package includes `api.php` routes, allowing you to interact with the data t
| GET | `/api/search/wilaya/{q}` | Search Wilayas by name or Arabic name |
| GET | `/api/search/commune/{q}` | Search Communes by name or Arabic name |

### API Availability Toggle

You can enable or disable the Algerian Cities API endpoints by setting the following option in your `.env` file:

```dotenv
ALGERIAN_CITIES_API_ENABLED=false # Default: true
```

----

## Future Planned Features

- [ ] Add support for Dairas (districts), including relationships with Wilayas and Communes
Expand Down
9 changes: 9 additions & 0 deletions config/algerian-cities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [

/**
* Enable or disable the Algerian Cities API
*/
'api_enabled' => env('ALGERIAN_CITIES_API_ENABLED', true),
];
16 changes: 11 additions & 5 deletions src/Providers/AlgerianCitiesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ public function boot()
]);
}

// API
$this->loadRoutesFrom(__DIR__.'/../../routes/api.php');
// Config file
$this->publishes([
__DIR__.'/../../config/algerian-cities.php' => config_path('algerian-cities.php'),
], 'config');

if(config('algerian-cities.use_routes', true)) {
$this->loadRoutesFrom(__DIR__.'/../../routes/api.php');
}

require __DIR__.'/../helpers.php';
}
Expand All @@ -50,8 +56,8 @@ public function register()
* Uncomment this function call to load the config file.
* If the config file is also publishable, it will merge with that file
*/
// $this->mergeConfigFrom(
// __DIR__.'/../../config/algerian-cities.php', 'algerian-cities'
// );
$this->mergeConfigFrom(
__DIR__.'/../../config/algerian-cities.php', 'algerian-cities'
);
}
}
12 changes: 5 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kossa\AlgerianCities\Tests;

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;

Expand All @@ -14,7 +15,7 @@ class TestCase extends \Orchestra\Testbench\TestCase
{
use RefreshDatabase;

public function getEnvironmentSetUp($app)
public function getEnvironmentSetUp($app): void
{
$CreateCitiesTable = include __DIR__.'/../database/migrations/2024_10_26_000000_create_cities_table.php.stub';

Expand All @@ -26,13 +27,10 @@ public function getEnvironmentSetUp($app)

/**
* Include the package's service provider(s)
*
* @see https://packages.tools/testbench/basic/testcase.html#package-service-providers
*
* @param \Illuminate\Foundation\Application $app
* @return array
**
* @param Application $app
*/
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
\Kossa\AlgerianCities\Providers\AlgerianCitiesServiceProvider::class,
Expand Down

0 comments on commit 4993f75

Please sign in to comment.