laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

BindingResolutionException with all response() calls #1080

Closed haroldkyle closed 4 years ago

haroldkyle commented 4 years ago

Description:

All routes return error:

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Routing\RouteCollectionInterface] is not instantiable while building [Illuminate\Routing\Redirector, Illuminate\Routing\UrlGenerator]. in /home/harold/projects/work/git/sugar-api/vendor/laravel/framework/src/Illuminate/Container/Container.php:1011

Routes worked fine with Lumen 6.x, but appear to have problems with the new class Illuminate\Routing\UrlGenerator from Laravel 7.12.0.

Steps To Reproduce:

Fresh install, then I have a route whose controller simply responds: return response()->json($model).

The AppServiceProvider.php has the following, and it's Illuminate\Routing\Redirector that loads the Illuminate\Routing\UrlGenerator:

    public function register()
    {
        $this->app->singleton('Illuminate\Contracts\Routing\ResponseFactory', function ($app) {
            return new \Illuminate\Routing\ResponseFactory(
                $app['Illuminate\Contracts\View\Factory'],
                $app['Illuminate\Routing\Redirector']
            );
        });
    }
driesvints commented 4 years ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to report back and I'll gladly help you out and re-open this issue.

Thanks!

haroldkyle commented 4 years ago

Thanks, I'll let you know. In the meantime, is the workaround for ResponseFactory described here still necessary for Lumen? This is what triggers the Exception, after all.

pascalvgemert commented 3 years ago

@haroldkyle We experienced the same issues. We fixed it by replacing the workaround with:

$this->app->singleton('Illuminate\Contracts\Routing\ResponseFactory', function ($app) {
    return new \Laravel\Lumen\Http\ResponseFactory;
});