Skip to content

Commit 82d08f5

Browse files
authored
Resolve UrlGenerator using binding (#59)
1 parent d1b0af1 commit 82d08f5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: src/LocalizedRoutesServiceProvider.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use CodeZero\Localizer\Localizer;
1111
use CodeZero\Localizer\LocalizerServiceProvider;
1212
use Illuminate\Support\ServiceProvider;
13+
use Illuminate\Container\Container;
1314

1415
class LocalizedRoutesServiceProvider extends ServiceProvider
1516
{
@@ -104,19 +105,23 @@ protected function registerProviders()
104105
*/
105106
protected function registerUrlGenerator()
106107
{
107-
$this->app->singleton('url', function ($app) {
108+
$this->app->singleton('url', function () {
109+
$app = Container::getInstance();
110+
108111
$routes = $app['router']->getRoutes();
109112

110113
// The URL generator needs the route collection that exists on the router.
111114
// Keep in mind this is an object, so we're passing by references here
112115
// and all the registered routes will be available to the generator.
113116
$app->instance('routes', $routes);
114117

115-
$url = new UrlGenerator(
116-
$routes, $app->rebinding(
118+
$url = $app->make(UrlGenerator::class, [
119+
'routes' => $routes,
120+
'request' => $app->rebinding(
117121
'request', $this->requestRebinder()
118-
), $app['config']['app.asset_url']
119-
);
122+
),
123+
'assetRoot' => $app['config']['app.asset_url']
124+
]);
120125

121126
// Next we will set a few service resolvers on the URL generator so it can
122127
// get the information it needs to function. This just provides some of

0 commit comments

Comments
 (0)