Laravel 5.1 to 5.2 upgrade error - php

When I try to update our existing project from Laravel 5.1 to Laravel 5.2 using the official guide, I get an error after composer update when the post update
php artisan clear-compiled
is run. Here is the error.
Class Illuminate\Foundation\Composer does not exist
Has anyone had a similar problem? When I run composer update with the no scripts flag it updates regularly so it's a problem on the clear-compiled.
Below are my Service Providers and my composer.json file.
Service Providers
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
// Illuminate\Redis\RedisServiceProvider::class,
Vetruvet\PhpRedis\PhpRedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,
Intervention\Image\ImageServiceProvider::class,
Torann\GeoIP\GeoIPServiceProvider::class,
Jenssegers\Agent\AgentServiceProvider::class,
Barryvdh\Debugbar\ServiceProvider::class,
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"fzaninotto/faker": "^1.6#dev",
"laravelcollective/html": "5.2.*",
"laravelcollective/remote": "~5.2",
"kriswallsmith/assetic": "^1.3#dev",
"pda/pheanstalk": "^3.0#dev",
"aws/aws-sdk-php-laravel": "~3.0",
"illuminate/http": "~5.2",
"illuminate/session": "~5.2",
"illuminate/support": "~5.2",
"nesbot/carbon": "~1.18",
"guzzlehttp/guzzle": "~5.3|~6.0",
"vetruvet/laravel-phpredis": "dev-master",
"predis/predis": "^1.1#dev",
"laravel/socialite": "^3.0#dev",
"intervention/image": "^2.3#dev",
"brightcove/api": "^1.0#dev",
"torann/geoip": "dev-master",
"graham-campbell/throttle": "~5.1",
"jenssegers/agent": "^3.0#dev"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"symfony/dom-crawler": "~3.0",
"symfony/css-selector": "~3.0",
"barryvdh/laravel-debugbar": "^2.0#dev",
"laracasts/generators": "dev-master"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/nardev/laravel-vzaar.git"
}
],
"autoload": {
"classmap": [
"database",
"app/Models",
"app/Footgoll"
],
"files": [
"app/helpers.php"
],
"psr-4": {
"Myapp\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"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-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev",
"prefer-stable": true
}
When I run
grep -nH -d recurse 'Composer' bootstrap/ app/ config/
This is what is returned:
bootstrap/autoload.php:7:| Register The Composer Auto Loader
bootstrap/autoload.php:10:| Composer provides a convenient, automatically generated class loader
bootstrap/autoload.php:42:| when working locally. However we will need to load in the Composer
This is how the autoload.php file looks like:
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/
$compiledPath = __DIR__.'/cache/compiled.php';
if (file_exists($compiledPath)) {
require $compiledPath;
}
/*
|--------------------------------------------------------------------------
| Register The Workbench Loaders
|--------------------------------------------------------------------------
|
| The Laravel workbench provides a convenient place to develop packages
| when working locally. However we will need to load in the Composer
| auto-load files for the packages so that these can be used here.
|
*/
if (is_dir($workbench = __DIR__.'/../workbench'))
{
Xtwoend\Workbench\Starter::start($workbench);
}
Could it be something about the workbench?
Update: a really horrible fix of returning the Composer.php from 5.1 to vendor/laravel/framework/src/Illuminate/Foundation lets the app function normally but I really need a better solution, one which can be pushed onto production.

The error you get is all about the packages that you use. Since the Composer class' location is changed, it is failed to get located.
From the upgrade notes:
The Illuminate\Foundation\Support\Composer class has been moved to
Illuminate\Support\Composer.
Wait for the pull requests to get accepted, for instance the laracasts/generators package, which is included within your composer.json file, is one of the packages that is not yet compatible with Laravel 5.2
https://github.com/laracasts/Laravel-5-Generators-Extended/issues/81
Thus, one of the most commonly used package where this error is occured is the cviebrock/eloquent-sluggable.
https://github.com/cviebrock/eloquent-sluggable/issues/214.
There is nothing you can but wait for the pull requests to get accepted or just edit the vendor files which is not that cool option to do.

Try
php artisan optimize --force
If error continues delete vendor/compiled.php and then run the command above
This will recreate vendor/compiled.php class.
Command above deletes two files
The bootstrap/compiled.php file. This file is created when you
optimize classes. The app/storage/meta/services.json file. This file
is created as Laravel tries to optimize the loading of the service
providers your application uses.
Source
when I ran clear-compiled it deleted the vendor/compiled.php in my project.
Since You do not have no compiled class at all you may not delete it. This must be why you are having problems. Do not bother clearing compiled classes..
I am also upgrading a huge app from 4.2 to 5.0. problems problems.. :)

The bug is being identified and discussed here :
https://github.com/laravel/framework/issues/9678

It's probably the SocialiteServiceProvider, maybe others as well.
I had this problem last night when upgrading, a lot of serviceproviders have to upgrade their code to 5.2 as well.
AdamWathan\EloquentOAuthL5\Installation seems to use the Composer class directly, remove this service provider and you can continue the upgrade.

Try this:
composer update --no-scripts
It allowed me to see a detailed explanation of why composer update failed. For me I was updating to laravel 5.2 but forgot to also update "laravelcollective/html": "5.1.*" to "laravelcollective/html": "5.2.*".
Found here https://stackoverflow.com/a/36515184/922522

Welp, I just made a new laravel app with 5.2 and added all of the code and dependencies in again, seems to be working now.

Related

cant install cakephp 4 again

I have wamp64, php 7.4 and using composer I ran this from the console
composer create-project --prefer-dist "cakephp/app:^4.0" myapp
and
composer create-project --prefer-dist cakephp/app:~4.0 my_app_name
The installation cut out towards the end with this error
Script App\Console\Installer::postInstall handing the post create project cmd event terminated with an exception
[Symfony\Component\Console\Exception\RunTimeException\ Aborted
and some Symfony runtime exception when you get to the set folder permission y/n
It created this JSON file
{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "https://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"php": ">=7.2",
"cakephp/cakephp": "~4.2.0",
"cakephp/migrations": "^3.0",
"cakephp/plugin-installer": "^1.3",
"mobiledetect/mobiledetectlib": "^2.8"
},
"require-dev": {
"cakephp/bake": "^2.3",
"cakephp/cakephp-codesniffer": "~4.2.0",
"cakephp/debug_kit": "^4.4",
"josegonzalez/dotenv": "^3.2",
"phpunit/phpunit": "~8.5.0 || ^9.3",
"psy/psysh": "#stable"
},
"suggest": {
"markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
"dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan/Psalm compatibility.",
"phpstan/phpstan": "PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code."
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"check": [
"#test",
"#cs-check"
],
"cs-check": "phpcs --colors -p src/ tests/",
"cs-fix": "phpcbf --colors -p src/ tests/",
"stan": "phpstan analyse",
"test": "phpunit --colors=always"
},
"prefer-stable": true,
"config": {
"sort-packages": true
}
}
How to Fix Cakephp 4 Composer Install Error
(i didnt understand the solution to this)
Cakephp 4 Windows Installation Issues
It should be possible to get it to work. What Windows version do you use? Pro or Home? Which distribution? 2010?
Please make sure to navigate to the WAMP install folder and then specifically the www folder.
The command I use is this;
composer create-project --prefer-dist cakephp/app:~4.0 cake
It worked for me.
Alternatively, download Cakephp version 4.0, place the contents in the www folder, and configure it manually through the file /config/app.php. If you want, we can look at it together. There are not many people around me that can or want to work on Cakephp, so it'd be a pleasure. :)

ReflectionException thrown on composer update for a file that exists

To make this more interesting, things work just fine if I run composer dump-autoload -o but I am curious why would this throw an error when I run composer update in the first place? I need to get to the bottom of this. A quick fix doesn't make me happy internally.
aligajani at Alis-MBP in ~/Projects/saveeo on master ✗ [faaba41c] 4:53
> composer update
> php artisan clear-compiled
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Generating autoload files
> php artisan optimize
[ReflectionException]
Class Saveeo\Board\Observers\BoardEventListener does not exist
BoardEventListener.php (placed in Saveeo/Board/Observers)
<?php
namespace Saveeo\Board\Observers;
use Saveeo\Services\HashIds\Contracts\HashIds as HashIdService;
class BoardEventListener {
private $hashIdService;
public function __construct(HashIdService $hashIdService) {
$this->hashIdService = $hashIdService;
}
public function whenBoardIsCreated($event) {
$this->hashIdService->syncHashIdValueOnModelChanges($event, 'board');
}
public function whenBoardIsUpdated($event) {
$this->hashIdService->syncHashIdValueOnModelChanges($event, 'board');
}
public function subscribe($events) {
$events->listen(
'Saveeo\Board\Observers\Events\BoardHasBeenCreated',
'Saveeo\Board\Observers\BoardEventListener#whenBoardIsCreated'
);
$events->listen(
'Saveeo\Board\Observers\Events\BoardHasBeenUpdated',
'Saveeo\Board\Observers\BoardEventListener#whenBoardIsUpdated'
);
}
}
EventServiceProvider.php (placed in Saveeo/Providers)
<?php
namespace Saveeo\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* #var array
*/
protected $listen = [
//
];
/**
* The subscriber classes to register.
*
* #var array
*/
protected $subscribe = [
'Saveeo\Board\Observers\BoardEventListener',
];
/**
* Register any other events for your application.
*
* #param \Illuminate\Contracts\Events\Dispatcher $events
* #return void
*/
public function boot(DispatcherContract $events) {
parent::boot($events);
//
}
}
Here is the folder structure. Can't see anything wrong here?
https://imgur.com/BI44Lq6
Composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"firebase/php-jwt": "~2.0",
"guzzlehttp/guzzle": "5.*",
"guzzlehttp/oauth-subscriber": "0.2.0",
"laravel/socialite": "2.*",
"league/flysystem-aws-s3-v3": "~1.0",
"aws/aws-sdk-php": "3.*",
"bugsnag/bugsnag-laravel": "1.*",
"vinkla/hashids": "^2.3"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1",
"tymon/jwt-auth": "0.5.*",
"symfony/dom-crawler": "~3.0",
"symfony/css-selector": "~3.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Saveeo\\": "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"
}
}
It looks like we changed the autoloading namespace (manually, or by using artisan app:name) for the classes in the app/ directory from App (the default) to Saveeo in composer.json:
"autoload": {
"psr-4": {
"Saveeo\\": "app/"
}
},
This is perfectly fine to do when we understand the implications. We can see the issue described in the question when we take a look at the project's folder structure for the file that causes the exception (with the namespaces in parentheses):
app (Saveeo)
├── Saveeo (Saveeo\Saveeo)
│   ├── Board (Saveeo\Saveeo\Board)
│ │   ├── Observers (Saveeo\Saveeo\Board\Observers)
│ │ │   ├── BoardEventListener
└── ...
For compatibility with PSR-4, the namespace for BoardEventListener should be Saveeo\Saveeo\Board\Observers because it exists in the Saveeo/ directory nested under app/. PSR-4 autoloading implementations resolve class files based on file names and paths, not the namespaces declared in the files. [Composer does read the namespace from the class files to create an optimized classmap, as long as the top-level namespace matches. See update.]
If we don't want to change the directory structure of the application, and we also don't want to use two Saveeos in the namespace, we can configure Composer to merge both directories into the same namespace when it autoloads classes:
"autoload": {
"psr-4": {
"Saveeo\\": [ "app/", "app/Saveeo/" ]
}
},
...and remember to composer dump-autoload.
It works, but I don't recommend this in practice. It deviates from the PSR-4 standard, makes the application susceptible to namespace conflicts, and may be confusing to other people working on the project. I suggest that you flatten the Saveeo namespace and directory, or choose a different namespace for the classes in the nested directory.
...things work just fine if I run composer dump-autoload -o but I am curious why would this throw an error when I run composer update...?
When generating the autoloading cache file, Composer doesn't actually execute your code. However, the artisan optimize command, which runs after composer update in most Laravel applications (until 5.5), does boot the application to perform its operations, so the problem code executes and we see the exception.
Update:
If using Saveeo\Board\etc was wrong versus doing Saveeo\Saveeo\Board\etc then other files around the entire application wouldn't work, but they do.
We can technically use non-PSR-4 namespaces that don't match the project's directory structure when we generate an optimized autoloader like we would to prepare an application for production:
composer dump-autoload --optimize
This works because Composer will scan each class file for namespaces to create a static classmap. When we don't specify --optimize, Composer relies on dynamic autoloading which matches file paths to namespaces, so non-standard namespaces or directory structures fail to resolve.
The namespacing for the project in question works for the most part, even though it doesn't follow PSR-4, because we're manually dumping an optimized autoloader by using the -o option for dump-autoload. However, we see the error message because composer update removes the cached classmap before running the update, so, by the time the artisan optimize command runs, the classmap no longer contains the classes that we dumped.
We can configure Composer to always optimize the autoloader by setting the optimize-autoloader configuration directive in composer.json:
"config": {
"optimize-autoloader": true
}
...which should fix the install and update commands for this project. It's a bit of a hack to get non-standard namespacing to resolve. With this approach, remember that we'll need to dump the autoloader whenever we add a new file in development that doesn't follow PSR-4.
This seems to be related to the Composer PSR autoloading. By default Laravel will include
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
which means "the root of the App namespace is in the app folder, and from there match namespace to folder structure".
Your Saveeo namespace hasn't been registered (it's not in the App hierarchy), so Composer doesn't know its location.
It should work if you add another line to your composer.json (and then dump-autoload)
"autoload": {
"psr-4": {
"App\\": "app/",
"Saveeo\\": "app/Saveeo"
}
}
Alternatively, you could, as the other answer points out, just place the whole Saveeo namespace within App (so it's App\Saveeo\Board\Observers\Events\BoardHasBeenCreated for instance). However your Saveeo namespace seems to be sort of a self-contained module, it may be more reasonable to have it as a separate namespace rather than renaming the namespace in all of its files.
I believe if you just change your namespace to:
App\Saveeo\Board\Observers instead of Saveeo\Board\Observers
all your problems should be solved. Please let me know if you have a reason for creating this new namespace, instead of just branching out from the base App namespace.

Laravel 5.2 | Issue with bootstrap/cache/compiled.php

Good afternoon,
I had a time with a problem running composer update in my production repository. Only in production, in DEV and PRE does not happen to me, everyone has the same configuration and at the end pull almost the same repository and share composer.json
I'm using "laravel / framework": "5.2. *", With PHP 7.0
The problem I have is that when launching composer update, I generate this file, bootstrap / cache / compiled.php but only in PROD, in neither of the other versions generates it, nor in local. With this file loaded the application gives an error 500 and reports this failure:
PHP Fatal error: Can not declare class Illuminate \ Support \ ServiceProvider, because the name is already in use in /var/www/vhosts/proyecto/bootstrap/cache/compiled.php on line 5267
If I delete this file by hand the application works again, but this should not happen, in addition, the applications that I try to install with composer, since I have this bug, do not work, I declare them in config / app.php and check that this The folder in vendor and everything is correct, but it gives another 500 so the reason why it does not erase or generate bootstrap / cache / compiled.php makes the installations do not end up being correct.
Please, could you help me, I do not know what else to look or do ....
This is my composer file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"twbs/bootstrap": "^3.3",
"laravelcollective/html": "5.2.*",
"joshcam/mysqli-database-class": "dev-master",
"opentok/opentok": "2.3.x",
"intervention/image": "^2.3",
"hisorange/browser-detect": "2.*",
"ignited/laravel-omnipay": "2.*",
"omnipay/omnipay": "*",
"skecskes/calendar": "0.2.*",
"webpatser/laravel-uuid": "^2.0",
"barryvdh/laravel-debugbar": "^2.2",
"maatwebsite/excel": "~2.1.0",
"paypal/rest-api-sdk-php": "*",
"laracasts/flash": "^2.0",
"doctrine/dbal": "^2.5",
"laravel/cashier": "~6.0",
"barryvdh/laravel-dompdf": "0.7.*",
"dompdf/dompdf": "^0.7",
"ovh/ovh": "^2.0",
"docusign/esign-client": "^2.0",
"sentry/sentry": "^1.6",
"sentry/sentry-laravel": "^0.7.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"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"
}
Thank you very much,
greetings
Update 2017/06/15 08:00 CEST
Remove, one by one the third party package from the require/requir_dev section and retry composer update
Mostly, third party packages cause this error. You can do the following things:
Run php artisan clear-compiled and retry composer update
Remove the generated service provider from compiled.php and retry composer update
Make a fresh installation
You're using PHP 7.0. It's not forbidden (I recommend) to use a newer version of Laravel!

Fatal Error Laravel: Uncaught ReflectionException when i view my Site

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!

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

Categories