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"
}
}
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();
});
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']
);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With