Skip to content

Commit

Permalink
Merge pull request #5 from tormjens/master
Browse files Browse the repository at this point in the history
Enable changing the route group prefix
  • Loading branch information
inxilpro authored May 23, 2018
2 parents 0f5adf8 + 1d5af42 commit 1b70c75
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ You can get the countries list using a custom locale:
GET /galahad/addressing/countries?locale=pt
```

### Changing the route group prefix

By default the routes returning the JSON responses are prefixed with `galahad/addressing`. If you would like to change this, you need to publish the configuration file using `php artisan vendor:publish --provider="Galahad\LaravelAddressing\ServiceProvider"`. This will create a config file (`addressing.php`) in your `config` directory with:

```php
<?php

return [
'route' => [
'prefix' => 'countries' // change this to whatever you'd like
],
];
```


### Thanks!

Special thanks to [Commerce Guys](https://github.com/commerceguys) for their amazing [addressing](https://github.com/commerceguys/addressing) and [intl](https://github.com/commerceguys/intl) packages, which this project relies heavily on.
12 changes: 12 additions & 0 deletions config/addressing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Route Configuration
|--------------------------------------------------------------------------
*/
'route' => [
'prefix' => 'countries', // change this to whatever you'd like
],
];
19 changes: 13 additions & 6 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Class ServiceProvider
*
* @package Galahad\LaravelAddressing
* @author Chris Morrell
* @author Junior Grossi <[email protected]>
*/
Expand All @@ -24,6 +23,9 @@ public function boot()
{
$this->bootRoutes();
$this->loadTranslationsFrom(__DIR__.'/../lang', 'laravel-addressing');
$this->publishes([
__DIR__.'/../config/addressing.php' => config_path('addressing.php'),
]);
}

/**
Expand Down Expand Up @@ -51,7 +53,8 @@ protected function bootRoutes()

try {
$route = $this->app->make('router');
$route->group(['prefix' => 'galahad/addressing'], function ($route) {
$prefix = config('addressing.route.prefix', 'galahad/addressing');
$route->group(['prefix' => $prefix], function ($route) use ($prefix) {
$route->get('/{country}/administrative-areas', [
'as' => 'galahad.addressing.administrative-areas',
'uses' => '\\Galahad\\LaravelAddressing\\Controller@getAdministrativeAreas',
Expand Down Expand Up @@ -81,10 +84,14 @@ protected function registerValidators()
$validator->extend('country_name', CountryValidator::class.'@validateCountryName');

// Administrative Area validators
$validator->extend('administrative_area_code',
AdministrativeAreaValidator::class.'@validateAdministrativeAreaCode');
$validator->extend('administrative_area_name',
AdministrativeAreaValidator::class.'@validateAdministrativeAreaName');
$validator->extend(
'administrative_area_code',
AdministrativeAreaValidator::class.'@validateAdministrativeAreaCode'
);
$validator->extend(
'administrative_area_name',
AdministrativeAreaValidator::class.'@validateAdministrativeAreaName'
);
$validator->extend('administrative_area', AdministrativeAreaValidator::class.'@validateAdministrativeArea');

// Postal Code validator
Expand Down

0 comments on commit 1b70c75

Please sign in to comment.