Laravel 5 - Vendor - Class not found
Solution 1
I faced a similar problem. Uploading the vendor/composer folder worked for me !
Solution 2
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
.
Solution 3
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.
Comments
-
Phorce almost 2 years
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?