thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.77k stars 2.67k forks source link

Class 'App\Voyager' not found #1957

Closed MECU closed 6 years ago

MECU commented 6 years ago

Description:

During install into an existing Laravel 5.5, I got this error:

 [Symfony\Component\Debug\Exception\FatalThrowableError]
 Class 'App\Voyager' not found

After the migration process succeeded and the last success file was Seeding data into the database

I tried to run composer dumpautoload which errored out when it tried to run php artisan package:discover which gave the same error.

I then tried php artisan config:clear which gave the same error.

It seems the auto-register isn't working, though it did work successfully after the initial composer requre when the package:discover ran.

Steps To Reproduce:

composer require tcg/voyager
php artisan voyager:install

Full copy paste of console

vagrant@homestead:~/Code/xxx$ composer require tcg/voyager
Using version ^1.0 for tcg/voyager
./composer.json has been updated
> php artisan clear-compiled
The compiled services & packages files have been removed.
> php artisan horizon:pause
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 24 installs, 0 updates, 0 removals
  - Installing jakub-onderka/php-console-color (0.1): Downloading (100%)
  - Installing jakub-onderka/php-console-highlighter (v0.3.2): Downloading (100%)
  - Installing dnoegel/php-xdg-base-dir (0.1): Downloading (100%)
  - Installing psy/psysh (v0.8.11): Loading from cache
  - Installing laravel/tinker (v1.0.2): Loading from cache
  - Installing symfony/filesystem (v3.3.10): Downloading (100%)
  - Installing seld/phar-utils (1.0.1): Downloading (100%)
  - Installing seld/jsonlint (1.6.1): Downloading (100%)
  - Installing seld/cli-prompt (1.0.3): Downloading (100%)
  - Installing justinrainbow/json-schema (5.2.4): Downloading (100%)
  - Installing composer/spdx-licenses (1.1.6): Downloading (100%)
  - Installing composer/semver (1.4.2): Downloading (100%)
  - Installing composer/composer (1.5.2): Downloading (100%)
  - Installing larapack/hooks (v1.0.1): Downloading (100%)
  - Installing larapack/voyager-hooks (v1.0.3): Downloading (100%)
  - Installing arrilot/laravel-widgets (3.7.7): Downloading (100%)
  - Installing doctrine/collections (v1.5.0): Loading from cache
  - Installing doctrine/cache (v1.7.1): Loading from cache
  - Installing doctrine/annotations (v1.5.0): Loading from cache
  - Installing doctrine/common (v2.8.1): Loading from cache
  - Installing doctrine/dbal (v2.6.2): Loading from cache
  - Installing larapack/doctrine-support (v0.1.4): Downloading (100%)
  - Installing intervention/image (2.4.1): Downloading (100%)
  - Installing tcg/voyager (v1.0.5): Downloading (100%)
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)
doctrine/cache suggests installing alcaeus/mongo-php-adapter (Required to use legacy MongoDB driver)
intervention/image suggests installing ext-imagick (to use Imagick based image processing.)
intervention/image suggests installing intervention/imagecache (Caching extension for the Intervention Image library)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> php artisan package:discover
Discovered Package: hmazter/laravel-schedule-list
Discovered Package: laravelcollective/html
Discovered Package: maatwebsite/excel
Discovered Package: barryvdh/laravel-ide-helper
Discovered Package: laravel/horizon
Discovered Package: laravel/tinker
Discovered Package: arrilot/laravel-widgets
Discovered Package: intervention/image
Discovered Package: tcg/voyager
Package manifest generated successfully.
> php artisan horizon:continue
> php artisan clear-compiled
The compiled services & packages files have been removed.
> php artisan ide-helper:generate
A new helper file was written to _ide_helper.php
> php artisan ide-helper:meta
A new meta file was written to .phpstorm.meta.php
vagrant@homestead:~/Code/xxx$ php artisan voyager:install
Setting up the hooks
Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"
Publishing the Voyager assets, database, language, and config files
Copied Directory [/vendor/tcg/voyager/publishable/assets] To [/public/vendor/tcg/voyager/assets]
Copied Directory [/vendor/tcg/voyager/publishable/database/migrations] To [/database/migrations]
Copied Directory [/vendor/tcg/voyager/publishable/database/seeds] To [/database/seeds]
Copied Directory [/vendor/tcg/voyager/publishable/demo_content] To [/storage/app/public]
Copied File [/vendor/tcg/voyager/publishable/config/voyager.php] To [/config/voyager.php]
Copied Directory [/vendor/tcg/voyager/publishable/lang] To [/resources/lang]
Publishing complete.
Publishing complete.
Migrating the database tables into your application
Migrating: 2016_01_01_000000_add_voyager_user_fields
Migrated:  2016_01_01_000000_add_voyager_user_fields
Migrating: 2016_01_01_000000_create_data_types_table
Migrated:  2016_01_01_000000_create_data_types_table
Migrating: 2016_01_01_000000_create_pages_table
Migrated:  2016_01_01_000000_create_pages_table
Migrating: 2016_01_01_000000_create_posts_table
Migrated:  2016_01_01_000000_create_posts_table
Migrating: 2016_02_15_204651_create_categories_table
Migrated:  2016_02_15_204651_create_categories_table
Migrating: 2016_05_19_173453_create_menu_table
Migrated:  2016_05_19_173453_create_menu_table
Migrating: 2016_10_21_190000_create_roles_table
Migrated:  2016_10_21_190000_create_roles_table
Migrating: 2016_10_21_190000_create_settings_table
Migrated:  2016_10_21_190000_create_settings_table
Migrating: 2016_11_30_135954_create_permission_table
Migrated:  2016_11_30_135954_create_permission_table
Migrating: 2016_11_30_141208_create_permission_role_table
Migrated:  2016_11_30_141208_create_permission_role_table
Migrating: 2016_12_26_201236_data_types__add__server_side
Migrated:  2016_12_26_201236_data_types__add__server_side
Migrating: 2017_01_13_000000_add_route_to_menu_items_table
Migrated:  2017_01_13_000000_add_route_to_menu_items_table
Migrating: 2017_01_14_005015_create_translations_table
Migrated:  2017_01_14_005015_create_translations_table
Migrating: 2017_01_15_000000_add_permission_group_id_to_permissions_table
Migrated:  2017_01_15_000000_add_permission_group_id_to_permissions_table
Migrating: 2017_01_15_000000_create_permission_groups_table
Migrated:  2017_01_15_000000_create_permission_groups_table
Migrating: 2017_01_15_000000_make_table_name_nullable_in_permissions_table
Migrated:  2017_01_15_000000_make_table_name_nullable_in_permissions_table
Migrating: 2017_03_06_000000_add_controller_to_data_types_table
Migrated:  2017_03_06_000000_add_controller_to_data_types_table
Migrating: 2017_04_11_000000_alter_post_nullable_fields_table
Migrated:  2017_04_11_000000_alter_post_nullable_fields_table
Migrating: 2017_04_21_000000_add_order_to_data_rows_table
Migrated:  2017_04_21_000000_add_order_to_data_rows_table
Migrating: 2017_07_05_210000_add_policyname_to_data_types_table
Migrated:  2017_07_05_210000_add_policyname_to_data_types_table
Migrating: 2017_08_05_000000_add_group_to_settings_table
Migrated:  2017_08_05_000000_add_group_to_settings_table
Attempting to set Voyager User model as parent to App\User
Dumping the autoloaded files and reloading all new files
Adding Voyager routes to routes/web.php
Seeding data into the database

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'App\Voyager' not found

vagrant@homestead:~/Code/xxx$ composer dumpautoload
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> php artisan package:discover

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'App\Voyager' not found

Script php artisan package:discover handling the post-autoload-dump event returned with error code 1

vagrant@homestead:~/Code/xxx$ php artisan config:clear

  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Class 'App\Voyager' not found
MECU commented 6 years ago

Seems like the root cause was this in routes/web.php

Route::group(['prefix' => 'admin'], function () {
    Voyager::routes();
});
fletch3555 commented 6 years ago

Not sure why that isn't working for you. The Voyager Facade is registered by VoyagerServiceProvider, which is autoloaded correctly per the logs you posted.

fletch3555 commented 6 years ago

@MECU, is this still an issue for you? I haven't seen any other similar complaints, so it's most likely something you've done as opposed to a bug in Voyager. If you're still having issues and have more information to provide, please do so and we'll reopen this. Thank you.

kitsunekyo commented 6 years ago

@fletch3555 i'd like to note that i have the exact same issue.

its working perfectly fine on homestead but when moving the package to the remote, I get Class 'Voyager' not found in routes/web.php, which is where i add the Voyager routes.

homestead: php 5.6.32-l+ubuntu16.04

remote: php 5.6.30-0+deb8ul

rest is exactly the same. most recent composer version, flushed the vendor file and did a composer install again on the remote. but i always get the above error.

fletch3555 commented 6 years ago

Do you have terminal access to that remote server? Can you confirm that the VoyagerServiceProvider is loaded?

kitsunekyo commented 6 years ago

thanks for replying so quickly. :) yes. i do have terminal access.

what i've done now is paste the vendor and bootstrap contents manually per scp on the client server. and now it works.

it might have something to do with the composer install.

is a php artisan voyager:install required for deploys? shouldnt be right? i already have it installed on my homestead, migrated the db manually

fletch3555 commented 6 years ago

As long as you copy everything (including vendor and the database), No, voyager:install won't be needed. Having said that, you may run into issues if your local instance isn't a perfect match to the remote. If you install packages that expect php 7.1 because that's what you have locally, then push that to your remote with 7.0, it could very easily break. For this reason, I would recommend not pushing vendor and running composer install on the remote server. Just make sure composer.lock is pushed so you get the expected versions.

github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.