Skip to content

Commit 8853db6

Browse files
committed
Add route group feature
1 parent 4ace5cc commit 8853db6

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/LaravelLocale/LocaleRouter.php

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace KiaKing\LaravelLocale;
44

5+
use Closure;
56
use Illuminate\Contracts\Config\Repository as Config;
67
use Illuminate\Contracts\Routing\Registrar as Router;
78

@@ -124,4 +125,26 @@ protected function generateRoutes($method, $uri, $action)
124125

125126
$this->router->{$method}($uri, $action);
126127
}
128+
129+
/**
130+
* Create a route group with shared attributes prefixing with locale.
131+
*
132+
* @param array $attributes
133+
* @param Closure $callback
134+
* @return void
135+
*/
136+
public function group(array $attributes, Closure $callback)
137+
{
138+
$this->router->group($attributes, $callback);
139+
140+
$availables = $this->config->get('locale.available_locales');
141+
142+
foreach ($availables as $locale) {
143+
$newAttributes = $attributes;
144+
145+
$newAttributes['prefix'] = isset($attributes['prefix']) ? "$locale/{$attributes['prefix']}" : $locale;
146+
147+
$this->router->group($newAttributes, $callback);
148+
}
149+
}
127150
}

0 commit comments

Comments
 (0)