Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
some refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
reziamini committed Oct 23, 2020
1 parent fceae8d commit c944d00
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/.vscode
/.idea
build
composer.lock
docs
vendor
coverage
.phpunit.result.cache
coverage.clover
.php_cs.cache
.php_cs.cache
12 changes: 7 additions & 5 deletions src/BalootFakerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
38 changes: 21 additions & 17 deletions src/BalootServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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();
Expand Down Expand Up @@ -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();
});
}
}
}

0 comments on commit c944d00

Please sign in to comment.