Skip to content

Commit

Permalink
Merge pull request #22 from sbtsrbayer/master
Browse files Browse the repository at this point in the history
Set missing route to be generated last
  • Loading branch information
lesichkovm committed Jul 5, 2018
2 parents aa8c0d1 + e3464e3 commit bb5fc61
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/AdvancedRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,14 @@ public static function controller($path, $controllerClassName) {
return (strcmp($a->slug, $b->slug));
});

$addMissingMethod = false;
foreach ($methods as $method) {
$slug = $method->slug;
$methodName = $method->name;
$slug_path = $path . '/' . $slug;

if($methodName == 'missingMethod')
{
$slug_path = str_replace('//', '/', $path.'/'.'{_missing}');
Route::any($slug_path, $controllerClassName . '@' . $methodName);

$route = new \stdClass();
$route->httpMethod = 'any';
$route->prefix = sprintf("Route::%-4s('%s',", 'any', $slug_path);
$route->target = $controllerClassName . '@' . $methodName;
$routes[] = $route;
if ($methodName == 'missingMethod') {
$addMissingMethod = true;
continue;
}

Expand All @@ -89,6 +82,20 @@ public static function controller($path, $controllerClassName) {
}
}

// add the _missing route last otherwise it will be hit by routes whose
// method names start with a letter greater than the letter 'm'
if ($addMissingMethod) {
$methodName = 'missingMethod';
$slug_path = str_replace('//', '/', $path.'/'.'{_missing}');
Route::any($slug_path, $controllerClassName . '@' . $methodName);

$route = new \stdClass();
$route->httpMethod = 'any';
$route->prefix = sprintf("Route::%-4s('%s',", 'any', $slug_path);
$route->target = $controllerClassName . '@' . $methodName;
$routes[] = $route;
}

if (self::EMIT_ROUTE_STATEMENTS) {
self::emitRoutes($routes);
}
Expand Down

0 comments on commit bb5fc61

Please sign in to comment.