Skip to content

When namespaces begin with \ they should reset. #18078

@AlbertMarashi

Description

@AlbertMarashi
  • Laravel Version: 5,4

Description:

I'm working with the Laravel Passport.

In my code I have this:

Route::group(['namespace' => 'SomeNamespace'], function(){ //App\Http\Controllers\SomeNamespace
    Route::get('', function(){
        return 'something';
    });
    
    \Laravel\Passport\Passport::routes();
});

I've been getting the error:

[ReflectionException]
Class App\Http\Controllers\SomeNamespace\Laravel\Passport\Http\Controllers\AuthorizationController does not exist

Now I've found the problem, which lies in the Passport.php file

   /**
     * Get a Passport route registrar.
     *
     * @param  array  $options
     * @return RouteRegistrar
     */
    public static function routes($callback = null, array $options = [])
    {
        $callback = $callback ?: function ($router) {
            $router->all();
        };

        $options = array_merge($options, [
            'namespace' => '\Laravel\Passport\Http\Controllers', //Here
        ]);

        Route::group($options, function ($router) use ($callback) {

            $callback(new RouteRegistrar($router));
        });
    }

As you can see at //Here the namespace doesn't reset, like normal php would.

I understand that if it was Laravel\... instead of \Laravel\... it would make sense but this goes against php standards, wouldn't you agree?

I'll try find the problem in the Route files and create a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions