thedevdojo / voyager

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

php artisan db:seed --class=VoyagerDatabaseSeeder is not norking. Throwing erro ReflectionException : Class VoyagerDatabaseSeeder does not exist. #4415

Closed igoralves1 closed 4 years ago

igoralves1 commented 5 years ago

Version information

Description

Following instructions from the official page in the Advanced part when I run php artisan db:seed --class=VoyagerDatabaseSeeder I am getting an error (see below).

Steps To Reproduce

Steps to reproduce the behavior:

  1. Go to 'the official website https://voyager-docs.devdojo.com/getting-started/installation'
  2. After php artisan voyager:install
  3. go to 'Advanced' and run php artisan vendor:publish --provider="TCG\Voyager\VoyagerServiceProvider" AND php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5" AND php artisan migrate AND perform tha changes in USER class and route.
  4. When I run the next step php artisan db:seed --class=VoyagerDatabaseSeeder I get the follow error:

    ReflectionException  : Class VoyagerDatabaseSeeder does not exist
    
    at /home/ila/vhosts/voyager2/vendor/laravel/framework/src/Illuminate/Container/Container.php:788
    784|         if ($concrete instanceof Closure) {
    785|             return $concrete($this, $this->getLastParameterOverride());
    786|         }
    787| 
    > 788|         $reflector = new ReflectionClass($concrete);
    789| 
    790|         // If the type is not instantiable, the developer is attempting to resolve
    791|         // an abstract type such as an Interface or Abstract Class and there is
    792|         // no binding registered for the abstractions so we need to bail out.
    
    Exception trace:
    
    1   ReflectionClass::__construct("VoyagerDatabaseSeeder")
      /home/ila/vhosts/voyager2/vendor/laravel/framework/src/Illuminate/Container/Container.php:788
    
    2   Illuminate\Container\Container::build("VoyagerDatabaseSeeder")
      /home/ila/vhosts/voyager2/vendor/laravel/framework/src/Illuminate/Container/Container.php:667
    
    Please use the argument -v to see more details.

Expected behavior

No error. Should have the database initialized with some basic data

Note:

If then I run php artisan voyager:install --with-dummy everything works good, even the command that was generating the error. Here you have the output:

php artisan voyager:install --with-dummy
Publishing the Voyager assets, database, and config files
Copied Directory [/vendor/tcg/voyager/publishable/database/seeds] To [/database/seeds]
Publishing complete.
Publishing complete.
Migrating the database tables into your application
Nothing to migrate.
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
Publishing dummy content
Copied Directory [/vendor/tcg/voyager/publishable/database/dummy_seeds] To [/database/seeds]
Copied Directory [/vendor/tcg/voyager/publishable/dummy_content] To [/storage/app/public]
Copied Directory [/vendor/tcg/voyager/publishable/database/migrations] To [/database/migrations]
Publishing complete.
Migrating dummy tables
Migrating: 2016_01_01_000000_create_pages_table
Migrated:  2016_01_01_000000_create_pages_table (0.58 seconds)
Migrating: 2016_01_01_000000_create_posts_table
Migrated:  2016_01_01_000000_create_posts_table (0.44 seconds)
Migrating: 2016_02_15_204651_create_categories_table
Migrated:  2016_02_15_204651_create_categories_table (1.37 seconds)
Migrating: 2017_04_11_000000_alter_post_nullable_fields_table
Migrated:  2017_04_11_000000_alter_post_nullable_fields_table (0.62 seconds)
Seeding dummy data
Setting up the hooks
Copied File [/vendor/larapack/hooks/publishable/config/hooks.php] To [/config/hooks.php]
Publishing complete.
Hooks are now ready to use! Go ahead and try to "php artisan hook:install test-hook"
Adding the storage symlink to your public folder
The [public/storage] directory has been linked.
Successfully installed Voyager! Enjoy
ila@ila:~/vhosts/voyager2(master)**$ php artisan db:seed --class=VoyagerDatabaseSeeder**
Database seeding completed successfully.
emptynick commented 5 years ago

You either run php artisan voyager:install or do the advanced steps. Not both.

JoseGeorges8 commented 5 years ago

I resolved this by modifying my DatabaseSeeder to include the content of the VoyagerDatabaseSeeder. Specifically:

use TCG\Voyager\Traits\Seedable;

right bellow class definition:

  use Seedable;

    protected $seedersPath = __DIR__.'/';

inside the run method:

 $this->seed('DataTypesTableSeeder');
        $this->seed('DataRowsTableSeeder');
        $this->seed('MenusTableSeeder');
        $this->seed('MenuItemsTableSeeder');
        $this->seed('RolesTableSeeder');
        $this->seed('PermissionsTableSeeder');
        $this->seed('PermissionRoleTableSeeder');
        $this->seed('SettingsTableSeeder');

Not sure why, but I did the installation manually as I had an already existing application.

d-sko commented 4 years ago

Hi, just FYI: I had the same problem and in my case I just had to do a composer dump-autoload before running the seeder.

altwaireb commented 4 years ago

if you change locale in config/app.php

Return it to

'locale' => 'en', then composer dump-autoload php artisan voyager:install

moh1434 commented 3 years ago

i still get this error on laravel8. i installed voyager using 'php artisan voyager:install --with-dummy' now i need to run only voyager seeder but i get 'Class VoyagerDatabaseSeeder does not exist.' 'composer dump-autoload ' don't solve this problem :( note: i have 'database/seeds' folder which contain all voyager seeders

IvAndrew commented 3 years ago

i still get this error on laravel8. i installed voyager using 'php artisan voyager:install --with-dummy' now i need to run only voyager seeder but i get 'Class VoyagerDatabaseSeeder does not exist.' 'composer dump-autoload ' don't solve this problem :( note: i have 'database/seeds' folder which contain all voyager seeders

  1. Move all voyager files from seeds to seeders
  2. Add to each of them namespace Database\Seeders;
  3. Edit files VoyagerDatabaseSeeder.php and VoyagerDummyDatabaseSeeder.php - see https://github.com/the-control-group/voyager/pull/5093/files (you need remove use Seedable; and change run method)
  4. Run seed again
mtshikomba commented 3 years ago

i still get this error on laravel8. i installed voyager using 'php artisan voyager:install --with-dummy' now i need to run only voyager seeder but i get 'Class VoyagerDatabaseSeeder does not exist.' 'composer dump-autoload ' don't solve this problem :( note: i have 'database/seeds' folder which contain all voyager seeders

  1. Move all voyager files from seeds to seeders
  2. Add to each of them namespace Database\Seeders;
  3. Edit files VoyagerDatabaseSeeder.php and VoyagerDummyDatabaseSeeder.php - see https://github.com/the-control-group/voyager/pull/5093/files (you need remove use Seedable; and change run method)
  4. Run seed again

For Laravel 8 you need to make below changes for Seeding to work :-

Add Database\Seeders namespace at top of DatabaseSeeder.php and other Seeder files :-

namespace Database\Seeders; Replace folder name seeds to seeders located at \database\ folder.

Update composer.json like below:

This worked for me, but I had to add this to my composer.json file and run composer dumpautoload


"autoload": {
    "psr-4": {
         .
         .
         .
        "Database\\Seeders\\": "database/seeders/"
    }
}```
rahiid commented 3 years ago

if you change locale in config/app.php

Return it to

'locale' => 'en', then composer dump-autoload php artisan voyager:install

Thank you, This worked.

github-actions[bot] commented 2 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.