Showing posts with label lumen. Show all posts
Showing posts with label lumen. Show all posts

Friday, September 7, 2018

Target [Illuminate\Contracts\Routing\ResponseFactory] is not instantiable on calling Response::json using Response Facade in Lumen 5.4.3

Target [Illuminate\Contracts\Routing\ResponseFactory] is not instantiable on calling Response::json using Response Facade in Lumen 5.4.3


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

Found a fix from tymondesigns/jwt-auth#532
In bootstrap/app.php uncomment this line $app->register(App\Providers\AppServiceProvider::class);
In the file App\Providers\AppServiceProvider 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']
            );
        });
        // ...
    }

ReflectionException' with message 'Class path.storage does not exist

after run:
 php artisan migrate

got this errors:
PHP Fatal error:  Uncaught ReflectionException: Class path.storage does not exist in C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
Stack trace:
#0 C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Container\Container.php(752): ReflectionClass->__construct('path.storage')
#1 C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Container\Container.php(631): Illuminate\Container\Container->build('path.storage')
#2 C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Container\Container.php(586): Illuminate\Container\Container->resolve('path.storage', Array)
#3 C:\xampp\htdocs\lumen\iq-api\vendor\laravel\lumen-framework\src\Application.php(230): Illuminate\Container\Container->make('path.storage', Array)
#4 C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(110): Laravel\Lumen\Application->make('path.storage', Array)

#5 C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Fo in C:\xampp\htdocs\lumen\iq-api\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 752


In my case (lumen 5.3.3) got fixed by adding following lines right after $app definition in bootstrap/app.php file:
$app = new Laravel\Lumen\Application(
        realpath(__DIR__ . '/../')
);

$app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
$app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');

//$app->withFacades();
$app->withEloquent();
Summery is only add following two lines,
$app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
$app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');