Skip to content

Commit 9b68dd5

Browse files
Skullbockivanvermeyen
authored andcommitted
Register the UrlGenerator the same way Laravel does (#2)
* Register the UrlGenerator the same way Laravel does In recent versions, Laravel added a few changes to the url generator registration. Made the same changes here * Update UrlGenerator.php
1 parent 2d22e4d commit 9b68dd5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/LocalizedRoutesServiceProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function mergeConfig()
8282
*
8383
* @return void
8484
*/
85-
protected function registerUrlGenerator()
85+
protected function registerUrlGenerator ()
8686
{
8787
$this->app->singleton('url', function ($app) {
8888
$routes = $app['router']->getRoutes();
@@ -95,13 +95,20 @@ protected function registerUrlGenerator()
9595
$url = new UrlGenerator(
9696
$routes, $app->rebinding(
9797
'request', $this->requestRebinder()
98-
)
98+
), $app['config']['app.asset_url']
9999
);
100100

101+
// Next we will set a few service resolvers on the URL generator so it can
102+
// get the information it needs to function. This just provides some of
103+
// the convenience features to this URL generator like "signed" URLs.
101104
$url->setSessionResolver(function () {
102105
return $this->app['session'];
103106
});
104107

108+
$url->setKeyResolver(function () {
109+
return $this->app->make('config')->get('app.key');
110+
});
111+
105112
// If the route collection is "rebound", for example, when the routes stay
106113
// cached for the application, we will need to rebind the routes on the
107114
// URL generator instance so it has the latest version of the routes.

src/UrlGenerator.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
class UrlGenerator extends BaseUrlGenerator
1313
{
1414
/**
15-
* Create a new UrlGenerator instance.
15+
* Create a new URL Generator instance.
1616
*
17-
* @param \Illuminate\Routing\RouteCollection $routes
18-
* @param \Illuminate\Http\Request $request
17+
* @param \Illuminate\Routing\RouteCollection $routes
18+
* @param \Illuminate\Http\Request $request
19+
* @param string $assetRoot
20+
* @return void
1921
*/
20-
public function __construct(RouteCollection $routes, Request $request)
22+
public function __construct(RouteCollection $routes, Request $request, $assetRoot = null)
2123
{
22-
parent::__construct($routes, $request);
24+
parent::__construct($routes, $request, $assetRoot);
2325
}
2426

2527
/**

0 commit comments

Comments
 (0)