Here's my code
if (empty($errors))
{
/* Success case */
}
else
{
$response = array('success' => false, 'errors' => $errors);
}
return Response::json($response);
Here's the error
in Container.php line 804
at Container->notInstantiable('Illuminate\\Contracts\\Routing\\ResponseFactory') in Container.php line 687
at Container->build('Illuminate\\Contracts\\Routing\\ResponseFactory') in Container.php line 565
at Container->make('Illuminate\\Contracts\\Routing\\ResponseFactory') in Application.php line 208
at Application->make('Illuminate\\Contracts\\Routing\\ResponseFactory') in Container.php line 1070
at Container->offsetGet('Illuminate\\Contracts\\Routing\\ResponseFactory') in Facade.php line 159
at Facade::resolveFacadeInstance('Illuminate\\Contracts\\Routing\\ResponseFactory') in Facade.php line 128
at Facade::getFacadeRoot() in Facade.php line 215
at Facade::__callStatic('json', array(array(***))) in AppResponse.php line 31
Use Response::json using Response Facade to return responses.
Same error calling response() and response()->json()
the workaround is returning new \Illuminate\Http\Response($response) or new \Illuminate\Http\JsonResponse($response)
Found a fix from tymondesigns/jwt-auth#532
In bootstrap/app.php uncomment this line
$app->register(App\Providers\AppServiceProvider::class);
In the file AppProvidersAppServiceProvider update the register method to add:
/**
* Register any application services.
*/
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']
);
});
// ...
}
Thanks @ismaail !
Awesome sauce, thanks @ismaail . But note there's a missing opening ( on the return new \Illuminate\Routing\ResponseFactory line, in case that gave someone issues.
Thanks @andela-kakpobome, typo fixed
is there any information about this? this shouldn't be needed for a normal setup
@taylorotwell should we introduce this into the framework better?
adding
$this->app->singleton('Illuminate\Contracts\Routing\ResponseFactory', function ($app) {
return new \Illuminate\Routing\ResponseFactory(
$app['Illuminate\Contracts\View\Factory'],
$app['Illuminate\Routing\Redirector']
);
});
works but feels hacky!
For those still getting an error, put that code in bootstrap/app.php AND install the dependency:
composer require illuminate/routing
btw, I feel my Lumen installation is less and less lightweight, depending more and more on Laravel's components
Lumen depends too much on Laravel soo much that I also feel its better to just use Laravel :)
unless we doing something wrong
I think this problem is not a Lumen problem but this is the same as this comment: issue 504 comment from lsl
To quote him:
This seems to happen when laravel/framework gets required by something, composer wipes out lumens vendor/illuminate files with vendor/laravel/framework (laravel/framework composer.json says replace illuminate.) - this in turn includes illuminate/Foundation/helpers.php
Removing the offending package and removing the vendor directory and composer.lock file. Than running composer update solves the problem.
There is no need to add the above mentioned code.
As detailed by @pevawi, removing the vendor directory and running composer update works for me on Lumen 5.6 with following error:
Target [Illuminate\Contracts\Translation\Translator] is not instantiable.
@libasoles Thanks brother you just saved me..
This seems to be fixed in 5.7 so please upgrade. Thanks for reporting.
Still getting 'Target is not instantiable' error
(1/1)聽BindingResolutionException
in聽Container.php聽line 945
at聽Container->notInstantiable('Illuminate\Contracts\Filesystem\Factory')in聽Container.php聽line 785
at聽Container->build('Illuminate\Contracts\Filesystem\Factory')in聽Container.php聽line 658
at聽Container->resolve('Illuminate\Contracts\Filesystem\Factory',聽array())in聽Container.php聽line 609
at聽Container->make('Illuminate\Contracts\Filesystem\Factory',聽array())in聽Application.php聽line 260
Most helpful comment
Found a fix from tymondesigns/jwt-auth#532
In bootstrap/app.php uncomment this line
$app->register(App\Providers\AppServiceProvider::class);In the file AppProvidersAppServiceProvider update the register method to add: