Fatal Error Laravel: Uncaught ReflectionException when i view my Site - php

I have the following error when i view my site.
My Error:
Fatal error: Uncaught ReflectionException: Class log does not exist in
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php:741> Stack trace: #0
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(741):
ReflectionClass->__construct('log') #1
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(631):
Illuminate\Container\Container->build('log', Array) #2
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674):
Illuminate\Container\Container->make('log', Array) #3
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(842):
Illuminate\Foundation\Application->make('log') #4
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(805):
Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) > #5 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(774):
Il in
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php
on line 741
My Composer.json file is like this
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"doctrine/dbal": "v2.4.2",
"swiftmailer/swiftmailer": "^5.4",
"guzzlehttp/guzzle": "~5.3|~6.0",
"chrisbjr/api-guard": "^2.3",
"serverfireteam/panel": "1.3.*",
"laravel/socialite": "^2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"files": [
"app/Http/helpers.php",
"app/Support/helpers.php"
],
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Anyone help me how to get rid of this error and view my site successfully.

Delete all files in bootstrap/cache/ then run:
composer dump-autoload -o

I had a similar issue. I found that to really dig down into the issue, you need to modify the Illuminate/Container/Container.php file, as suggested here at the third from the top.
<?php
namespace {
use Monolog\Logger as Monolog;
class log extends Illuminate\Log\Writer {
function __construct()
{
$this->monolog = new Monolog("local");
}
}
}
namespace Illuminate\Container {
use Closure;
use ArrayAccess;
use ReflectionClass;
use ReflectionMethod;
use ReflectionFunction;
use ReflectionParameter;
use InvalidArgumentException;
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Contracts\Container\BindingResolutionException as BindingResolutionContractException;
class Container implements ArrayAccess, ContainerContract
{
Modify it as the code suggests, and add an additional closing bracket to the bottom. This will allow it to display the error that it otherwise has been unable to display and thus be able to fix your problem!

Delete vendor file and then run composer update

I found the solution, in my routes i don't called exactly the name of the Controller
Example:
Route::get('/endpoint', 'Namebadcontroller#function');
// Correct name of route
Route::get('/endpoint', 'NameBadController#function');
And run the follow commands:
composer dump-autoload -o
php artisan clear-compiled
php artisan optimize

The issue might originate from a package that is not (yet) downloaded in your vendor folder (with all installed vendor packages)
In that case composer dump-autoload -o does not fix your issue.
Check you composer.json and composer.lock.
I added main into my branch from a GIT repo.
composer.json and composer.lock did not match!
The resolution was to recover composer.json and composer.lock from main and readded all changes from my branch manually.
Just to be sure I also removed my vendor folder.
Running composer install (re)installed all packages stored in composer.lock and added all (newer) not yet installed.
Notice that running composer update might fix the issue, but alse updates packages that perhaps may not be updated.

Try the command composer dump-autoload -o.
I used it to overcome the problem: 'Uncaught ReflectionException'.
Good luck!

Related

Composer auto generated wrong path

I am building a website with Laravel 5.
Laravel is using Composer as dependency management.
Whenever I run composer dump-autoload the autoload classes are generated.
Unfortunately the path in two of these files are wrong.
I am using one Seed class and some migrations within Laravel which is located in database/seeds respectively database/migrations.
The generated paths to all classes (migrations, seeds) below the database folder is wrong.
The path looks like $baseDir . '/atabase/migrations/2017_02_02_153131_create_cards_table.php'
As you can see the "d" from "database" is missing.
As far as I know the autoload classes are defined in the composer.json file.
But here it seems to be correct:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
}
The migration is working, but the seeds are not.
When I do a search&replace and correct the path everything is fine unless I do composer dump-autoload
I am developing on a Windows 10 machine with Laravel 5.4.8 and Composer 1.3.2.
Edit:
Here is the output of composer dump-autoload -vvv
PS C:\Users\phoef\Documents\Projekte\CardViewer> composer dump-autoload -vvv
Reading ./composer.json
Loading config file ./composer.json
Checked CA file C:\Users\phoef\AppData\Local\Temp\composer-cacert- 300c74d6960d46715ffed607c8e36acfa7cbcad49862bb1b67d3c43dea9bfb40.pem: valid
Executing command (C:\Users\phoef\Documents\Projekte\CardViewer): git branch --no-color --no-abbrev -v
Reading C:/Users/phoef/AppData/Roaming/Composer/composer.json
Loading config file C:/Users/phoef/AppData/Roaming/Composer/composer.json
Reading C:\Users\phoef\Documents\Projekte\CardViewer/vendor/composer/installed.json
Reading C:/Users/phoef/AppData/Roaming/Composer/vendor/composer/installed.json
Running 1.3.2 (2017-01-27 18:23:41) with PHP 7.1.1 on Windows NT / 10.0
Generating autoload files
The two files containg the wrong path are: autoload_classmap.php and autoload_static.php.
Edit 2:
Please find below the complete composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true
}
}
The seeds and migrations live in the database/ directory (from project root), not inside app/. Do you'll have database/seeds/CardsTableSeeder.php, for example.
Did you create them using artisan?
php artisan make:migration create_cards_table
php artisan make:seed CardsTableSeeder
It's not required to do it this way but it's handy to be sure you get them in the right directory.
Here's my autoload, you're missing the psr-4 key.
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
}
I have noidea why it's doing atabase, sorry
You are doing something wrong. You need to reset project and start from start.

Fatal error: Class ... not found in ... /ProviderRepository.php on line 146

This sounds like a trivial mistake, but I've been unable to find the solution for hours.
I tried to use https://github.com/michaelbonds/laravel-db2 in my Laravel project, and I added it using composer.
Here's my composer.json.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"michaelb/laravel-db2": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Here's the error:
PHP Fatal error: Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found in /var/www/html/mysjsu/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
and
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found
I found a similar question before on StackOverflow, and somebody suggested that the order matters. So, here's what I did in the following order:
add "michaelb/laravel-db2": "~2.0" to composer.json
run php ../composer.phar update
add MichaelB\Database\DB2\DB2ServiceProvider::class to the providers arary in config/app.php
run php artisan migrate
Any idea on what might've been the problem?
This package is a fork of cooperl/laravel-db2. The documentation is inaccurate.
He changed the namespace to MichaelB but never tagged this as a stable version, so when you composer require his ~2.0, packagist gives you an older version with the wrong namespace.
So when you run composer update, it runs some post-cmd scripts such as php artisan optimize which tries to pull from the config file but fails because that class doesn't exist.
Here's how to fix it:
Change composer.json to this version:
"michaelb/laravel-db2": "dev-master"
Run composer update --no-scripts
Then you should be good.

Laravel 5 - Vendor - Class not found

I am using laravel-analytics (https://github.com/spatie/laravel-analytics/) and have installed everything locally, works fine.
Whenever I try to upload to the server, however, I get the following error visiting the page: Class 'LaravelAnalytics' not found and I am trying to access it via: use \LaravelAnalytics as Analytics;
I am using both linux operating systems, both locally and on the server. I have also ran: composer update and now get: Nothing to install or update
I have checked the .json file and I can see the package I am trying to install is there.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"illuminate/html": "5.*",
"spatie/laravel-analytics": "^1.2"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"files":
["app/Http/helpers.php"],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Anyone have any ideas to what I am missing or where I am going wrong?
I faced a similar problem. Uploading the vendor/composer folder worked for me !
Being myself confronted with this problem, I first would like to thank riza who put me on the path.
According to the documentation, after installed the service provider and facade, we have to do this command :
php artisan vendor:publish --provider="Spatie\Analytics\AnalyticsServiceProvider"
Which causes the following error : Class 'Spatie\Analytics\AnalyticsServiceProvider' not found
If we see into vendor/spatie/laravel-analytics/src, we can see that the required classes contain Laravel string at the beginning of their names.
Solution :
So to solve this error, we need to change the call made from the config/app.php file :
providers section. Change this :
Spatie\Analytics\AnalyticsServiceProvider::class,
by :
Spatie\LaravelAnalytics\LaravelAnalyticsServiceProvider::class,
aliases section, change this :
'Analytics' => Spatie\Analytics\AnalyticsFacade::class,
by :
'Analytics' => Spatie\LaravelAnalytics\LaravelAnalyticsFacade::class,
Then, run again the following command, to make it work (added Laravel string too) :
php artisan vendor:publish --provider="Spatie\LaravelAnalytics\LaravelAnalyticsServiceProvider"
Then go to config/ folder. You should see a file called laravel-analytics.php.
I had similar problem when I created own package. PHP Storm was finding class but when scripts started then status 500 was shown. The reason was simple - be sure that your package from vendor include in it's composer.json
"autoload": {
"classmap": [
"src/"
]
}
Then it will be autoloaded.
Change your psr-4 to this:
"psr-4": {
"App\\": "app/",
"vendor\\spatie\\" : "spatie/"
}
hope this work for you.
You have to add the class to the aliases (or use the FQCN):
// config/app.php
'aliases' => [
...
'LaravelAnalytics' => 'Spatie\LaravelAnalytics\LaravelAnalyticsFacade',
...
];
"require: {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"illuminate/html": "5.*",
"spatie/laravel-analytics": "^1.2"**
}
Seems that you are using the php 5.* and that's why composer pulling the 1.2 version of the package which has different class.
I got the same problem a month ago
The read me file that you read to setup package is for 2.4 version which is for php 7.0
Just update your php 5.* to php 7.* or get the read me file of 1.2 version of package to setup package correctly
For details see my blog: Class not found error due to php version mismatch

Fzaninotto Faker Install package

Can you help me with this error in laravel? I ran php artisan db:seed --class=UserTableSeeder and got:
PHP Fatal error:
Class 'Faker\Factory' not found in /Users/I/Laravel/authapp/app/database/seeds
/UserTableSeeder.php on line 7
{
"error":{
"type":"Symfony\\Component\\Debug\\Exception \\FatalErrorException",
"message":"Class 'Faker\\Factory' not found",
"file":"\/Users /I\/Laravel\/authapp\/app\/database\/seeds\/UserTableSeeder.php",
"line":7
}
}
My UserTableSeeder.php
<?php
class UserTableSeeder extends Seeder
{
public function run()
{
$faker = Faker\Factory::create();
User::truncate();
foreach(range(1,30) as $index)
{
User::create([
'username' => str_replace('.', '_', $faker->unique()->userName),
'email' => $faker->email,
'password' => 'password',
]);
}
}
}
My composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*#dev"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable",
"require-dev": {
"fzaninotto/faker": "1.3.*#dev"
},
}
After adding the comma, I still get the same error and If I try to include it using autoload from github it also does not work. Where could I look for the error?
I still get the same error. I am scared that it is not loading the Fzniotto Faker Package. What can I do? If I try to include the package by downlaoding it, I get
PHP Warning: Uncaught exception 'ErrorException' with message 'require_once(../../../vendor/Faker/autoload.php): failed to open stream: No such file or directory' in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php:6
Stack trace:
#0 /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php(6): Illuminate\Exception\Handler->handleError(2, 'require_once(.....', '/Users/stefanie...', 6, Array)
#1 /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php(6): UserTableSeeder::run()
#2 /Users/stefanieness/Laravel/authapp/vendor/laravel/framework/src/Illuminate/Database/Console/SeedCommand.php(57): UserTableSeeder->run()
#3 /Users/stefanieness/Laravel/authapp/vendor/laravel/framework/src/Illuminate/Console/Command.php(112): Illuminate\Database\Console\SeedCommand->fire()
#4 /Users/stefanieness/Laravel/authapp/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), O in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php on line 6
PHP Fatal error: UserTableSeeder::run(): Failed opening required '../../../vendor/Faker/autoload.php' (include_path='/Users/stefanieness/Laravel/authapp/vendor/phpseclib/phpseclib/phpseclib:.:') in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php on line 6
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"UserTableSeeder::run(): Failed opening required '..\/..\/..\/vendor\/Faker\/autoload.php' (include_path='\/Users\/stefanieness\/Laravel\/authapp\/vendor\/phpseclib\/phpseclib\/phpseclib:.:')","file":"\/Users\/stefanieness\/Laravel\/authapp\/app\/database\/seeds\/UserTableSeeder.php","line":6}}SEICCN-3:authapp stefanieness$
Yup, you forgot a comma
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*#dev"
},
then run composer update
I still get the same error. I am scared that it is not loading the Fzniotto Faker Package. What can I do?
In your shell, try running php artisan dump-autoload.
Run composer update, you are however missing a comma in your composer.json;
"require": {
"laravel/framework": "4.2.*"
"fzaninotto/faker": "1.3.*#dev"
}
Should be;
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*#dev"
}
If you already have the dependency and copied the code wrong try running composer dump-autoload.
However, I now no longer get an error, but I also do not get any users in my table. It seems to be simply not working, eg. the table is not created and filled with lorem ipsum users. What can I do?
Have you created your users table?
If not you need to;
Run php artisan migrate:make create_users_table.
In your app/database/migrations folder you will find your new migration file.
Build your migration (http://laravel.com/docs/4.2/schema).
Run php artisan migrate.
Run php artisan db:seed.

Laravel: Issues with ServiceProvider | Error: Class '...ServiceProvider' not found in bootstrap/compiled.php on line #

I have been working on the same app for a little bit now, and I am moving it over to Laravel. This is not only my first experience with Laravel, but my first time using a PHP framework. It is awesome so far.
I have run into a problem in my testing, I am getting an error: Error Output: PHP Fatal error: Class 'my-app/Repositories/RepositoryServiceProvider' not found in /var/www/laravel/bootstrap/compiled.php on line 4259
I am wondering what causes this error and how I can fix it . It gives me the direct line that is problematic. But I have no idea how to solve this issue.
I have tried a number of solutions including
composer install
composer update
composer dump-autoload
and others as well.
I have also attempted deleting the compiled.php file all together, but then it trips the same error on a different file. What is it causing this error, and how can I go about debugging it?
This is my RepositoryServiceProvider.php file that is being problematic:
<?php namespace my-app\Repositories;
use Invite;
use Illuminate\Support\ServiceProvider;
use my-app\Repositories\Invite\EloquentInviteRepository;
class RepositoryServiceProvider extends ServiceProvider {
/**
* Register the Invite Repository
*
* #return void
*/
public function registerInviteRepository()
{
$this->app->bind('my-app\Repositories\Invite\InviteRepository', function($app)
{
return new EloquentInviteRepository( new Invite );
});
}
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"way/generators": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
This is the specific line in compiled.php that is giving the issue:
{
return new $provider($app);
}
You guys have been a huge resource in the past.
I've experienced almost 24 hours of coding downtime because of this probably simple problem, and I've restored and rebuilt twice, only getting back to this error.
Thanks for help in advance!!
Have you tried registering your provider under 'providers' array of /app/cofig/app.php then do a composer dump-autoload -o

Categories