Alana Storm
Alana Storm

Reputation: 166056

Laravel -- Route Name Replaced with Full URI?

I'm working on a developer tool (closed source at the moment, unfortunately) that reports on Laravel route names. It does so with code that works mostly like this (this is simplified to make asking this question easier).

function identifyRoute() {
    $router = app('router');
    $route  = $router->current();

    $name   = $route->name;
    if($name) {
        return $name;
    }

    $action = $route->getAction();
    if(isset($action["controller"]) && $action["controller"]) {
        return $action["controller"];
    }

    if($name = $route->uri())
    {
        return $name;
    }

    return 'Could Not Identify Name';
}

So, for a route like

Route::get('foo/{id}/bar', function($id ) {
    //...      
});

Our function returns the string foo/{id}/bar. Or, it usually returns the string foo/{id}/bar. We've had reports from users that sometimes this method of identifying routes returns results like

foo/1234/bar
foo/1235/bar
foo/1236/bar
foo/1237/bar             

That is, it's returning the entire URI for the request.

Is there some Laravel setting (or popular extension/plugin) that could replace the results of calls to getName, uri, or the controller name, with the full URI of the request?

Upvotes: 0

Views: 171

Answers (1)

Aken Roberts
Aken Roberts

Reputation: 13447

A bit of a guess, but an OPTIONS HTTP request will return a 200 response with the proper allowable verbs, using the requested path as-is instead of a pattern.

Current source code in 5.7

Method is almost the same in 5.4.9

Upvotes: 2

Related Questions