8
8
use Illuminate \Routing \Router ;
9
9
use Illuminate \Routing \UrlGenerator ;
10
10
use Illuminate \Support \Collection ;
11
+ use Illuminate \Support \Facades \URL ;
11
12
use Illuminate \Support \Str ;
12
13
use Illuminate \View \Factory ;
13
14
use ReflectionProperty ;
@@ -54,7 +55,9 @@ public function handle()
54
55
$ this ->forcedScheme = (new ReflectionProperty ($ this ->url , 'forceScheme ' ))->getValue ($ this ->url );
55
56
$ this ->forcedRoot = (new ReflectionProperty ($ this ->url , 'forcedRoot ' ))->getValue ($ this ->url );
56
57
57
- $ routes = collect ($ this ->router ->getRoutes ())->map (function (BaseRoute $ route ) {
58
+ $ globalUrlDefaults = collect (URL ::getDefaultParameters ())->filter (fn ($ v ) => is_scalar ($ v ) || is_null ($ v ));
59
+
60
+ $ routes = collect ($ this ->router ->getRoutes ())->map (function (BaseRoute $ route ) use ($ globalUrlDefaults ) {
58
61
$ defaults = collect ($ this ->router ->gatherRouteMiddleware ($ route ))->map (function ($ middleware ) {
59
62
if ($ middleware instanceof \Closure) {
60
63
return [];
@@ -65,7 +68,7 @@ public function handle()
65
68
return $ this ->urlDefaults [$ middleware ];
66
69
})->flatMap (fn ($ r ) => $ r );
67
70
68
- return new Route ($ route , $ defaults , $ this ->forcedScheme , $ this ->forcedRoot );
71
+ return new Route ($ route , $ globalUrlDefaults -> merge ( $ defaults) , $ this ->forcedScheme , $ this ->forcedRoot );
69
72
});
70
73
71
74
if (! $ this ->option ('skip-actions ' )) {
@@ -344,6 +347,12 @@ private function getDefaultsForMiddleware(string $middleware)
344
347
}
345
348
346
349
$ methodContents = str ($ methodContents )->after ('{ ' )->beforeLast ('} ' )->trim ();
350
+
351
+ return $ this ->extractUrlDefaults ($ methodContents );
352
+ }
353
+
354
+ private function extractUrlDefaults (string $ methodContents ): array
355
+ {
347
356
$ tokens = token_get_all ('<?php ' .$ methodContents );
348
357
$ foundUrlFacade = false ;
349
358
$ defaults = [];
0 commit comments