Skip to content

Commit dacfe71

Browse files
authored
fix routing
fix routing
1 parent 0bb2ad5 commit dacfe71

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/ImageFitServiceProvider.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ class ImageFitServiceProvider extends ServiceProvider
1414
*/
1515
public function boot()
1616
{
17+
// Publish configuration files
1718
$this->publishes([
1819
__DIR__ . '/../files/config.php' => config_path('image-fit.php'),
19-
]);
20+
], 'config');
21+
22+
// HTTP routing
23+
if ((double) $this->app->version() >= 5.2) {
24+
$this->app['router']->get($this->app['config']->get('image-fit.prefix') . '{image}{type}{width}x{height}.{ext}', '\Amir2b\ImageFit\ImageController@create')
25+
->where(['image' => '(/[\w\-\.\(\)]+)+', 'type' => '_|-', 'width' => '\d+', 'height' => '\d+', 'ext' => 'jpe?g|png|gif|JPE?G'])
26+
->middleware('web');
27+
} else {
28+
$this->app['router']->get($this->app['config']->get('image-fit.prefix') . '{image}{type}{width}x{height}.{ext}', '\Amir2b\ImageFit\ImageController@create')
29+
->where(['image' => '(/[\w\-\.\(\)]+)+', 'type' => '_|-', 'width' => '\d+', 'height' => '\d+', 'ext' => 'jpe?g|png|gif|JPE?G']);
30+
}
2031
}
2132

2233
/**
@@ -30,10 +41,6 @@ public function register()
3041
__DIR__ . '/../files/config.php', 'image-fit'
3142
);
3243

33-
if (! $this->app->routesAreCached()) {
34-
Route::get($this->app['config']->get('image-fit.prefix') . '{image}{type}{width}x{height}.{ext}', 'Amir2b\ImageFit\ImageController@create')->where(['image' => '(/[\w\-\.\(\)]+)+', 'type' => '_|-', 'width' => '\d+', 'height' => '\d+', 'ext' => 'jpe?g|JPE?G|png|gif']);
35-
}
36-
3744
require_once __DIR__ . '/../files/helpers.php';
3845
}
3946
}

0 commit comments

Comments
 (0)