Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target [Illuminate\Contracts\Routing\ResponseFactory] is not instantiable

Tags:

lumen

I am trying to return a response like this:

return response()->json(['name' => 'Abigail', 'state' => 'CA']);

however, I got error:

Target [Illuminate\Contracts\Routing\ResponseFactory] is not instantiable.

Any idea?

Here is my composer.json:

{
  "name": "laravel/lumen",
  "description": "The Laravel Lumen Framework.",
  "keywords": [
    "framework",
    "laravel",
    "lumen"
  ],
  "license": "MIT",
  "type": "project",
  "require": {
    "php": ">=5.5.9",
    "laravel/lumen-framework": "5.2.*",
    "vlucas/phpdotenv": "~2.2",
    "generationtux/jwt-artisan": "^0.1.7",
    "barryvdh/laravel-cors": "^0.8.0",
    "neomerx/cors-illuminate": "^1.1",
    "fenos/notifynder": "3.1.*",
    "franzose/closure-table": "^4.1",
    "mlntn/lumen-artisan-serve": "~1",
    "guzzlehttp/guzzle": "~6.0",
    "league/flysystem": " ~1.0",
    "bugsnag/bugsnag-laravel": "^2.0"
  },
  "require-dev": {
    "fzaninotto/faker": "~1.4",
    "phpunit/phpunit": "~4.0"
  },
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "GuzzleHttp\\": "/vendor/guzzlehttp/"
    },
    "classmap": [
      "database/"
    ]
  },
  "autoload-dev": {
    "classmap": [
      "tests/",
      "database/"
    ]
  },
  "config": {
    "preferred-install": "dist"
  }
}
like image 689
simo Avatar asked Dec 21 '16 15:12

simo


2 Answers

I still get the error in 2020. Here's an updated version of the solution by @sunben:

In bootstrap/app.php, uncomment the following line

$app->register(App\Providers\AppServiceProvider::class);

Then in app\Providers\AppServiceProvider.php, update register method to add:

$this->app->singleton(\Illuminate\Contracts\Routing\ResponseFactory::class, function() {
    return new \Laravel\Lumen\Http\ResponseFactory();
});
like image 187
Rafał G. Avatar answered Sep 22 '22 15:09

Rafał G.


Might be late but found the solution.

In bootstrap/app.php, uncomment the following line

$app->register(App\Providers\AppServiceProvider::class);

Then in app\Providers\AppServiceProvider.php, update register method to add:

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']
        );
    });
}
like image 44
sunben Avatar answered Sep 22 '22 15:09

sunben