1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\Address; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
6
|
|
|
use Illuminate\Support\Facades\Route; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Yajra\Address\Controllers\BarangaysController; |
9
|
|
|
use Yajra\Address\Controllers\CitiesController; |
10
|
|
|
use Yajra\Address\Controllers\ProvincesController; |
11
|
|
|
use Yajra\Address\Controllers\RegionsController; |
12
|
|
|
use Yajra\Address\Repositories\Barangays\BarangaysRepository; |
13
|
|
|
use Yajra\Address\Repositories\Barangays\BarangaysRepositoryEloquent; |
14
|
|
|
use Yajra\Address\Repositories\Barangays\CachingBarangaysRepository; |
15
|
|
|
use Yajra\Address\Repositories\Cities\CachingCitiesRepository; |
16
|
|
|
use Yajra\Address\Repositories\Cities\CitiesRepository; |
17
|
|
|
use Yajra\Address\Repositories\Cities\CitiesRepositoryEloquent; |
18
|
|
|
use Yajra\Address\Repositories\Provinces\CachingProvincesRepository; |
19
|
|
|
use Yajra\Address\Repositories\Provinces\ProvincesRepository; |
20
|
|
|
use Yajra\Address\Repositories\Provinces\ProvincesRepositoryEloquent; |
21
|
|
|
use Yajra\Address\Repositories\Regions\CachingRegionsRepository; |
22
|
|
|
use Yajra\Address\Repositories\Regions\RegionsRepository; |
23
|
|
|
use Yajra\Address\Repositories\Regions\RegionsRepositoryEloquent; |
24
|
|
|
|
25
|
|
|
class AddressServiceProvider extends ServiceProvider |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Bootstrap services. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function boot() |
33
|
|
|
{ |
34
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
35
|
|
|
|
36
|
|
|
$this->mergeConfigFrom($config = __DIR__ . '/../config/address.php', 'address'); |
37
|
|
|
if ($this->app->runningInConsole()) { |
38
|
|
|
$this->publishes([$config => config_path('address.php')], 'address'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->setupRoutes(); |
42
|
|
|
|
43
|
|
|
$this->setupMacro(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function setupRoutes() |
47
|
|
|
{ |
48
|
|
|
Route::group([ |
49
|
|
|
'prefix' => config('address.prefix'), |
50
|
|
|
'middleware' => config('address.middleware'), |
51
|
|
|
'as' => 'address.', |
52
|
|
|
], function () { |
53
|
|
|
Route::get('regions', RegionsController::class . '@all')->name('regions.all'); |
54
|
|
|
Route::get('provinces', ProvincesController::class . '@all')->name('provinces.all'); |
55
|
|
|
Route::get('provinces/{regionId}', ProvincesController::class . '@getByRegion')->name('provinces.region'); |
56
|
|
|
Route::get('cities/{provinceId}', CitiesController::class . '@getByProvince')->name('cities.province'); |
57
|
|
|
Route::get('cities/{regionId}/{provinceId}', CitiesController::class . '@getByRegionAndProvince') |
58
|
|
|
->name('cities.region.province'); |
59
|
|
|
Route::get('barangays/{cityId}', BarangaysController::class . '@getByCity')->name('barangay.city'); |
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function setupMacro() |
64
|
|
|
{ |
65
|
|
|
Blueprint::macro('address', function () { |
66
|
|
|
$this->string('street'); |
|
|
|
|
67
|
|
|
$this->string('barangay_id', 10)->index(); |
|
|
|
|
68
|
|
|
$this->string('city_id', 10)->index(); |
|
|
|
|
69
|
|
|
$this->string('province_id', 10)->index(); |
|
|
|
|
70
|
|
|
$this->string('region_id', 10)->index(); |
|
|
|
|
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
Blueprint::macro('dropAddress', function () { |
74
|
|
|
$this->dropColumn(['region_id', 'province_id', 'city_id', 'barangay_id', 'street']); |
|
|
|
|
75
|
|
|
}); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Register services. |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function register() |
84
|
|
|
{ |
85
|
|
|
$this->app->singleton(RegionsRepository::class, function () { |
86
|
|
|
return new CachingRegionsRepository( |
87
|
|
|
$this->app->make(RegionsRepositoryEloquent::class), |
88
|
|
|
$this->app['cache.store'] |
89
|
|
|
); |
90
|
|
|
}); |
91
|
|
|
$this->app->singleton(ProvincesRepository::class, function () { |
92
|
|
|
return new CachingProvincesRepository( |
93
|
|
|
$this->app->make(ProvincesRepositoryEloquent::class), |
94
|
|
|
$this->app['cache.store'] |
95
|
|
|
); |
96
|
|
|
}); |
97
|
|
|
$this->app->singleton(CitiesRepository::class, function () { |
98
|
|
|
return new CachingCitiesRepository( |
99
|
|
|
$this->app->make(CitiesRepositoryEloquent::class), |
100
|
|
|
$this->app['cache.store'] |
101
|
|
|
); |
102
|
|
|
}); |
103
|
|
|
$this->app->singleton(BarangaysRepository::class, function () { |
104
|
|
|
return new CachingBarangaysRepository( |
105
|
|
|
$this->app->make(BarangaysRepositoryEloquent::class), |
106
|
|
|
$this->app['cache.store'] |
107
|
|
|
); |
108
|
|
|
}); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.