Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class Request does not exist in Illuminate/Container/Container.php #26229

Closed
DariusIII opened this issue Oct 23, 2018 · 32 comments
Closed

Class Request does not exist in Illuminate/Container/Container.php #26229

DariusIII opened this issue Oct 23, 2018 · 32 comments

Comments

@DariusIII
Copy link

  • Laravel Version: 5.7.10
  • PHP Version: 7.2.11
  • Database Driver & Version: MariaDB 10.3

Description:

After an update from laravel/framework 5.7.9 to version 5.7.10, site won't open anymore with following error in nginx/apache error log (tested on both):

PHP message: PHP Fatal error: Uncaught ReflectionException: Class request does not exist in localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
Stack trace:
#0 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('request')
#1 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(658): Illuminate\Container\Container->build('request')
#2 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(609): Illuminate\Container\Container->resolve('request', Array)
#3 localhost/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(733): Illuminate\Container\Container->make('request', Array)
#4 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(1222): Illuminate\Foundation\Application->make('request')
#5 localhost/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(112): Illuminate\Container...

If i downgrade to 5.7.9 everything works fine. No code was changed between, only the framework was updated.

Steps To Reproduce:

Update laravel/framework to version 5.7.10.

@staudenmeir
Copy link
Contributor

Please post the whole stacktrace.

@DariusIII
Copy link
Author

I'd love to, but that is all i got. On every server (three of them), stack trace has been stripped for some reason.

@staudenmeir
Copy link
Contributor

Are you using configuration caching (php artisan config:cache)?

@DariusIII
Copy link
Author

Here is the full stack trace:

PHP Fatal error: Uncaught ReflectionException: Class request does not exist in localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
Stack trace:
#0 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('request')
#1 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(658): Illuminate\Container\Container->build('request')
#2 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(609): Illuminate\Container\Container->resolve('request', Array)
#3 localhost/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(733): Illuminate\Container\Container->make('request', Array
#4 localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php(1222): Illuminate\Foundation\Application->make('request')
#5 localhost/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(112): Illuminate\Container\Container->offsetGet('request')
#6 in localhost/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 779

Yes i do use config caching, but i never had an issue, and i am using laravel in my project since 5.4.

@staudenmeir
Copy link
Contributor

Just to rule it out: Run php artisan config:clear.

@DariusIII
Copy link
Author

Unfortunately, that did not solve the issue.

@laurencei
Copy link
Contributor

laurencei commented Oct 24, 2018

I notice it says Class request and not Class Request

Looks like a local error, where you have incorrectly named a class somewhere. It might work on your local machine (i.e. Windows) - but on production it might be case sensitive (i.e. Ubuntu).

@sisve
Copy link
Contributor

sisve commented Oct 24, 2018

You mention that you see the error in "nginx/apache error log", do you have another error log with the full stacktrace? Like the one in the application's storage/logs folder?

The request is added to the container very early in the lifecycle. You can found it in public/index.php in a call to $kernel->handle which calls Kernel::sendRequestThroughRouter. If it fails before this, then I would suspect you have another problem than just a missing entry in the container.

Anyhow, check for a log file that contains all the nested exceptions too, you probably have some. Also, try editing HandleExceptions::handleException to var_dump the message and stacktrace to see what's going on. This would give you details in case you do have a problem with your exception handler.

@DariusIII
Copy link
Author

All the development is done on Ubuntu, server runs on Ubuntu. I have also noticed that it is not Request but request class that laravel is complaining about.

But if there is an typo somewhere, shouldn't that cause problems with any version, not just the latest?

Anyway, it was late yesterday to do extensive debugging, but now i can do it and see if its local, since nobody else reported it, and the error pops out as soon as i try to open the site, which means that it is triggered right on start.

@DariusIII
Copy link
Author

Closing the issue, problem was definitely local. Permissions on bootstrap/cache folder needed to be adjusted(once again) to allow proper functioning.

@telkins
Copy link
Contributor

telkins commented Sep 18, 2019

FWIW, I'm experiencing something similar, and getting the same error. For my particular case, the stack trace leads through this code in Illuminate\Http\Resources\Json\JsonResource:

    public function response($request = null)
    {
        return $this->toResponse(
            $request ?: Container::getInstance()->make('request')
        );
    }

Now, I'm not (yet) sure why this is breaking. For me, it's while running tests. I can make one HTTP request from my test and all is well, then second one triggers this same error, however.

I'm not sure that this is worth re-opening...yet. I've spent a lot of time on this so far, but I've not made much headway. Also, I'm on PHPUnit 7.5.16 (although I just switched back from 8.x thinking it may have had something to do with PHPUnit) and Laravel Framework 6.0.3.

@telkins
Copy link
Contributor

telkins commented Sep 18, 2019

Sorry...I also wanted to point out with the code above that the difference between request and Request isn't necessarily because of an error on the user's part. (I'm experiencing similar errors with config.

Another interesting note...I've got around 125 tests across 6 test classes that work fine, making HTTP request after HTTP request. But, my 7th test class seems to have a problem. There are few differences in the test classes themselves. There's a lot of repetitive tests for the various API resources. The code for the resource with the failing tests does do some things differently....like dispatching jobs.

I've still got to dig a bit more...and other than the error being the same and coming from a line of code that seems to work fine everywhere else, I'm not sure my particular problem is related...yet.

@ahmedabdelraouf
Copy link

make sure to use Laravel Controller and extend it this actulally the issue for me

@robertholf
Copy link

When I have this issue, I just composer update and it goes away.

@karl-roberts
Copy link

Okay so I encountered the same issue here. I feel the pain.

@staudenmeir 's php artisan config:clear worked for me, but before that I did try a composer update this boggles me. Although I am new to the intricacies of docker and environments.

Hope this helps someone out there, I nearly gave up tonight..

@ayenewdemeke
Copy link

I notice it says Class request and not Class Request

Looks like a local error, where you have incorrectly named a class somewhere. It might work on your local machine (i.e. Windows) - but on production it might be case sensitive (i.e. Ubuntu).

This was my problem, you saved my day. Thank you

@wishbone-productions
Copy link

or try clearing bootstrap/cache dir.

@ghost
Copy link

ghost commented Jun 10, 2020

PHP Fatal error: Declaration of Illuminate\Foundation\Exceptions\Handler::repor
t(Exception $e) must be compatible with Illuminate\Contracts\Debug\ExceptionHand
ler::report(Throwable $e) in C:\xampp\htdocs\javashop\vendor\laravel\framework\s
rc\Illuminate\Foundation\Exceptions\Handler.php on line 24
PHP Fatal error: Uncaught ReflectionException: Class App\Exceptions\Handler doe
s not exist in C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate
Container\Container.php:805
Stack trace:
#0 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Container\Co
ntainer.php(805): ReflectionClass->__construct('App\Exceptions\...')
#1 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Container\Co
ntainer.php(687): Illuminate\Container\Container->build('App\Exceptions\...')
#2 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foundation\A
pplication.php(796): Illuminate\Container\Container->resolve('App\Exceptions\.
..', Array, false)
#3 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Container\Co
ntainer.php(265): Illuminate\Foundation\Application->resolve('App\Exceptions\.
..', Array, false)
#4 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Container\Co
ntainer.php(801): Illuminate\Container\Container->Illuminate\Container{closure}
(Object(Illu in C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate
\Container\Container.php on line 807

can anyone help me with this error

@sisve
Copy link
Contributor

sisve commented Jun 10, 2020

@Shailabk24 Did you recently upgrade to Laravel 7? Your error looks like they are documented in the upgrade notes. https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades

@ghost
Copy link

ghost commented Jun 10, 2020

@Shailabk24 Did you recently upgrade to Laravel 7? Your error looks like they are documented in the upgrade notes. https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades

yeah my laravel version is 7.2.31 but my php artisan isn't working at all

@ghost
Copy link

ghost commented Jun 11, 2020

@Shailabk24 Did you recently upgrade to Laravel 7? Your error looks like they are documented in the upgrade notes. https://laravel.com/docs/7.x/upgrade#symfony-5-related-upgrades

sir upgraded the latest version but now again there's an error
PHP Fatal error: Uncaught TypeError: Argument 1 pass
ed to Illuminate\Foundation\Exceptions\Handler::shouldntReport() must be an inst
ance of Illuminate\Foundation\Exceptions\Exception, instance of TypeError given,
called in C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foun
dation\Exceptions\Handler.php on line 61 and defined in C:\xampp\htdocs\javashop
\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php:91
Stack trace:
#0 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foundation\E
xceptions\Handler.php(61): Illuminate\Foundation\Exceptions\Handler->shouldntRep
ort(Object(TypeError))
#1 C:\xampp\htdocs\javashop\app\Exceptions\Handler.php(40): Illuminate\Foundatio
n\Exceptions\Handler->report(Object(TypeError))
#2 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foundation\B
ootstrap\HandleExceptions.php(88): App\Exceptions\Handler->report(Object(TypeErr
or))
#3 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handle
Exception(Object(TypeE in C:\xampp\htdocs\javashop\vendor\laravel\framework\src
Illuminate\Foundation\Exceptions\Handler.php on line 91
[Thu Jun 11 20:09:21 2020] PHP Fatal error: Uncaught TypeError: Argument 1 pass
ed to Illuminate\Foundation\Exceptions\Handler::shouldntReport() must be an inst
ance of Illuminate\Foundation\Exceptions\Exception, instance of Symfony\Componen
t\ErrorHandler\Error\FatalError given, called in C:\xampp\htdocs\javashop\vendor
\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php on line 61 a
nd defined in C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\F
oundation\Exceptions\Handler.php:91
Stack trace:
#0 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foundation\E
xceptions\Handler.php(61): Illuminate\Foundation\Exceptions\Handler->shouldntRep
ort(Object(Symfony\Component\ErrorHandler\Error\FatalError))
#1 C:\xampp\htdocs\javashop\app\Exceptions\Handler.php(40): Illuminate\Foundatio
n\Exceptions\Handler->report(Object(Symfony\Component\ErrorHandler\Error\FatalEr
ror))
#2 C:\xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foundation\B
ootstrap\HandleExceptions.php(88): App\Exceptions\Handler->report(Object( in C:
xampp\htdocs\javashop\vendor\laravel\framework\src\Illuminate\Foundation\Excepti
ons\Handler.php on line 91
please help me out anyone

@christoferd
Copy link

christoferd commented Jun 18, 2020

or try clearing /bootstrap/cache dir.

(delete the php files in that directory/folder)

It's hard to believe that this actually worked. :-o

I had already run php artisan optimize, config:cache, config:clear ....
How is it that optimize did not automatically delete those files before running? :-/

And the error Illuminate\Contracts\Container\BindingResolutionException
No help whatsoever.
This error happened from just installing Laravel Blog demo, and the UI Auth scaffold.

@mfn
Copy link
Contributor

mfn commented Jun 21, 2020

How is it that optimize did not automatically delete those files before running? :-/

Because it's a bit of a chicken and egg problem. I commented this elsewhere, but forget where :}

Those files are an intrinsic part for the "laravel boot" process and thus it happens already before any artisan command is executed.

This means if an artisan command would exist to delete those files, and those cache files contain outdated information preventing Laravel from booting properly, you wouldn't get that far to actually delete them.

@asolopovas
Copy link

I am still getting this problem in a docker container and nothing works to fix it.

@mahadihassanrazib
Copy link

I notice it says Class request and not Class Request

Looks like a local error, where you have incorrectly named a class somewhere. It might work on your local machine (i.e. Windows) - but on production it might be case sensitive (i.e. Ubuntu).

100% worked for me. it was upper case lower case issue in my case. Thanks a lot

@kalpitgit
Copy link

kalpitgit commented Sep 23, 2020

This is a code issue...In my app.php code i had used if (in_array(request(), ['X.X.X.X']))
{
return false;
}. this is what was causing the issue

Just search for request() in all of your code lines

@mazPrzemo89
Copy link

Had a similar issue and referencing the Controller directly solved it. Route::get('/yourRoute', [App\Http\Controllers\SomeController::class, 'index'])->name('yourRoute');

@shubham110019
Copy link

Illuminate\Contracts\Container\BindingResolutionException

Target class [view.engine.resolver] does not exist.

at C:\Users\srall\Desktop\ecom\vendor\laravel\framework\src\Illuminate\Container\Container.php:811
807▕
808▕ try {
809▕ $reflector = new ReflectionClass($concrete);
810▕ } catch (ReflectionException $e) {
➜ 811▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
812▕ }
813▕
814▕ // If the type is not instantiable, the developer is attempting to resolve
815▕ // an abstract type such as an Interface or Abstract Class and there is

1 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation{closure}(Object(Facade\Ignition\IgnitionServiceProvider))

2 C:\Users\srall\Desktop\ecom\vendor\laravel\framework\src\Illuminate\Container\Container.php:809
ReflectionException::("Class view.engine.resolver does not exist")

@jhonnyer
Copy link

Tuve un problema similar y hacer referencia al controlador lo resolvió directamente. Route::get('/yourRoute', [App\Http\Controllers\SomeController::class, 'index'])->name('yourRoute');

A mi me funciono asi esa solución, o colocando directamente la ruta del controlador ejemplo:
Route::get('/inicio','App\Http\Controllers\ProductosController@index');

@hayjay
Copy link

hayjay commented May 4, 2022

I had a similar error like this : PHP Fatal error: Uncaught TypeError: Return value of Illuminate\\Container\\Container::offsetGet() must be an instance of Illuminate\\Container\\mixed

All I had to do was to check the installed php versions using sudo update-alternatives --list php

The result of that looks like this:

/usr/bin/php7.4
/usr/bin/php8.0

Since that error is a php 7 error, I had to disable php7.4 and enable php 8.0 by following the below steps:

  1. sudo a2dismod php7.4 -> disables php7.4
  2. sudo a2enmod php8.0 -> enables php8.0

Finally I had to restart apache2 for those changes to take effect using : systemctl restart apache2, you may need to restart your machine if the problem persist.

@nachom96
Copy link

nachom96 commented Dec 1, 2022

or try clearing /bootstrap/cache dir.

(delete the php files in that directory/folder)

It's hard to believe that this actually worked. :-o

I had already run php artisan optimize, config:cache, config:clear .... How is it that optimize did not automatically delete those files before running? :-/

And the error Illuminate\Contracts\Container\BindingResolutionException No help whatsoever. This error happened from just installing Laravel Blog demo, and the UI Auth scaffold.

Amazing

@christoferd
Copy link

I miss the days of vanilla PHP, where an error message would tell you exactly what the problem is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests