Skip to content

Commit 1bdfbe1

Browse files
committed
allows to prefix route
1 parent 7a77b51 commit 1bdfbe1

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

config/shorturl.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'route_form_prefix' => '',
5+
'route_redirect_prefix' => '',
6+
];

routes/web.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
Route::group(
44
[
55
'middleware' => ['web'],
6+
'prefix' => config('shorturl.route_form_prefix'),
67
],
78
function () {
89
Route::get('/', 'Gallib\ShortUrl\Http\Controllers\UrlController@create')->name('shorturl.url.create');
910
Route::post('/', 'Gallib\ShortUrl\Http\Controllers\UrlController@store')->name('shorturl.url.store');
10-
Route::get('/{code}', 'Gallib\ShortUrl\Http\Controllers\RedirectController@redirect')->name('shorturl.redirect');
1111
}
1212
);
13+
14+
Route::group(
15+
[
16+
'middleware' => ['web'],
17+
'prefix' => config('shorturl.route_redirect_prefix'),
18+
],
19+
function () {
20+
Route::get('/{code}', 'Gallib\ShortUrl\Http\Controllers\RedirectController@redirect')->name('shorturl.redirect');
21+
}
22+
);

src/Http/Requests/UrlRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ public function rules()
2929
$uniqueCode .= ',id,'.$this->get('id');
3030
}
3131

32+
$codeNotIn = config('shorturl.route_form_prefix') ? '|not_in:'.config('shorturl.route_form_prefix') : '';
33+
3234
return [
3335
'url' => 'required|url',
34-
'code' => 'max:255'.$uniqueCode,
36+
'code' => 'max:255'.$uniqueCode.$codeNotIn,
3537
];
3638
}
3739

src/ShortUrlServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public function boot()
1818
if ($this->app->runningInConsole()) {
1919
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
2020

21+
$this->publishes([
22+
__DIR__.'/../config/shorturl.php' => config_path('shorturl.php'),
23+
], 'shorturl-config');
24+
2125
$this->publishes([
2226
__DIR__.'/../resources/views' => base_path('resources/views/vendor/shorturl'),
2327
], 'shorturl-views');

0 commit comments

Comments
 (0)