1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Address; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Route; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Yajra\Address\Controllers\BarangaysController; |
8
|
|
|
use Yajra\Address\Controllers\CitiesController; |
9
|
|
|
use Yajra\Address\Controllers\ProvincesController; |
10
|
|
|
use Yajra\Address\Controllers\RegionsController; |
11
|
|
|
use Yajra\Address\Repositories\Barangays\BarangaysRepository; |
12
|
|
|
use Yajra\Address\Repositories\Barangays\BarangaysRepositoryEloquent; |
13
|
|
|
use Yajra\Address\Repositories\Barangays\CachingBarangaysRepository; |
14
|
|
|
use Yajra\Address\Repositories\Cities\CachingCitiesRepository; |
15
|
|
|
use Yajra\Address\Repositories\Cities\CitiesRepository; |
16
|
|
|
use Yajra\Address\Repositories\Cities\CitiesRepositoryEloquent; |
17
|
|
|
use Yajra\Address\Repositories\Provinces\CachingProvincesRepository; |
18
|
|
|
use Yajra\Address\Repositories\Provinces\ProvincesRepository; |
19
|
|
|
use Yajra\Address\Repositories\Provinces\ProvincesRepositoryEloquent; |
20
|
|
|
use Yajra\Address\Repositories\Regions\CachingRegionsRepository; |
21
|
|
|
use Yajra\Address\Repositories\Regions\RegionsRepository; |
22
|
|
|
use Yajra\Address\Repositories\Regions\RegionsRepositoryEloquent; |
23
|
|
|
|
24
|
|
|
class AddressServiceProvider extends ServiceProvider |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Bootstrap services. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function boot() |
32
|
|
|
{ |
33
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
34
|
|
|
|
35
|
|
|
$this->mergeConfigFrom($config = __DIR__ . '/../config/address.php', 'address'); |
36
|
|
|
if ($this->app->runningInConsole()) { |
37
|
|
|
$this->publishes([$config => config_path('address.php')], 'address'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->setupRoutes(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function setupRoutes() |
44
|
|
|
{ |
45
|
|
|
Route::group([ |
46
|
|
|
'prefix' => config('address.prefix'), |
47
|
|
|
'middleware' => config('address.middleware'), |
48
|
|
|
'as' => 'address.', |
49
|
|
|
], function () { |
50
|
|
|
Route::get('regions', RegionsController::class . '@all')->name('regions.all'); |
51
|
|
|
Route::get('provinces', ProvincesController::class . '@all')->name('provinces.all'); |
52
|
|
|
Route::get('provinces/{regionId}', ProvincesController::class . '@getByRegion')->name('provinces.region'); |
53
|
|
|
Route::get('cities/{provinceId}', CitiesController::class . '@getByProvince')->name('cities.province'); |
54
|
|
|
Route::get('cities/{regionId}/{provinceId}', CitiesController::class . '@getByRegionAndProvince') |
55
|
|
|
->name('cities.region.province'); |
56
|
|
|
Route::get('barangays/{cityId}', BarangaysController::class . '@getByCity')->name('barangay.city'); |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Register services. |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function register() |
66
|
|
|
{ |
67
|
|
|
$this->app->singleton(RegionsRepository::class, function () { |
68
|
|
|
return new CachingRegionsRepository( |
69
|
|
|
$this->app->make(RegionsRepositoryEloquent::class), |
70
|
|
|
$this->app['cache.store'] |
71
|
|
|
); |
72
|
|
|
}); |
73
|
|
|
$this->app->singleton(ProvincesRepository::class, function () { |
74
|
|
|
return new CachingProvincesRepository( |
75
|
|
|
$this->app->make(ProvincesRepositoryEloquent::class), |
76
|
|
|
$this->app['cache.store'] |
77
|
|
|
); |
78
|
|
|
}); |
79
|
|
|
$this->app->singleton(CitiesRepository::class, function () { |
80
|
|
|
return new CachingCitiesRepository( |
81
|
|
|
$this->app->make(CitiesRepositoryEloquent::class), |
82
|
|
|
$this->app['cache.store'] |
83
|
|
|
); |
84
|
|
|
}); |
85
|
|
|
$this->app->singleton(BarangaysRepository::class, function () { |
86
|
|
|
return new CachingBarangaysRepository( |
87
|
|
|
$this->app->make(BarangaysRepositoryEloquent::class), |
88
|
|
|
$this->app['cache.store'] |
89
|
|
|
); |
90
|
|
|
}); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|