diff --git a/.gitignore b/.gitignore index 72bec8b..4417908 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +/.vscode +/.idea build composer.lock docs @@ -5,4 +7,4 @@ vendor coverage .phpunit.result.cache coverage.clover -.php_cs.cache \ No newline at end of file +.php_cs.cache diff --git a/src/BalootFakerProvider.php b/src/BalootFakerProvider.php index 52031d9..0b7b512 100755 --- a/src/BalootFakerProvider.php +++ b/src/BalootFakerProvider.php @@ -14,11 +14,13 @@ public function customImage($path, $width, $height, $prefix = '') File::makeDirectory($path, 755, true); } $ch = curl_init("https://picsum.photos/{$width}/{$height}"); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt_array($ch, [ + CURLOPT_HEADER => 0, + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_BINARYTRANSFER => 1, + CURLOPT_TIMEOUT => 10, + CURLOPT_FOLLOWLOCATION => 1, + ]); $raw = curl_exec($ch); curl_close($ch); diff --git a/src/BalootServiceProvider.php b/src/BalootServiceProvider.php index 9055853..61c65b5 100644 --- a/src/BalootServiceProvider.php +++ b/src/BalootServiceProvider.php @@ -17,12 +17,6 @@ class BalootServiceProvider extends ServiceProvider */ public function boot() { - if (config('baloot.geo')) { - $this->loadMigrationsFrom([ - realpath(__DIR__.'/../database/migrations/2014_10_11_000000_create_provinces_table.php'), - realpath(__DIR__.'/../database/migrations/2014_10_11_000001_create_cities_table.php'), - ]); - } $this->publishes([ __DIR__.'/../config/config.php' => config_path('baloot.php'), @@ -33,17 +27,12 @@ public function boot() }); if (config('baloot.geo')) { - foreach (['city' => City::class, 'province' => Province::class] as $key => $model) { - Route::bind($key, function ($value) use ($model) { - return $model::where('slug', $value)->orWhere('id', $value)->firstOrFail(); - }); - Route::bind($key.'_by_slug', function ($value) use ($model) { - return $model::where('slug', $value)->firstOrFail(); - }); - Route::bind($key.'_by_id', function ($value) use ($model) { - return $model::where('id', $value)->firstOrFail(); - }); - } + $this->loadMigrationsFrom([ + realpath(__DIR__.'/../database/migrations/2014_10_11_000000_create_provinces_table.php'), + realpath(__DIR__.'/../database/migrations/2014_10_11_000001_create_cities_table.php'), + ]); + + $this->bindCityRoutes(); } $this->registerQueryBuilderMacros(); @@ -115,4 +104,19 @@ public function registerQueryBuilderMacros() return $this; }); } + + private function bindCityRoutes() + { + foreach (['city' => City::class, 'province' => Province::class] as $key => $model) { + Route::bind($key, function ($value) use ($model) { + return $model::where('slug', $value)->orWhere('id', $value)->firstOrFail(); + }); + Route::bind($key . '_by_slug', function ($value) use ($model) { + return $model::where('slug', $value)->firstOrFail(); + }); + Route::bind($key . '_by_id', function ($value) use ($model) { + return $model::where('id', $value)->firstOrFail(); + }); + } + } }