Asked  7 Months ago    Answers:  5   Viewed   39 times

As soon, I am typing php artisan db:seed command.

I'm getting Error Like:

[ReflectionException]
Class UserTableSeeder does not exist

root@dd-desktop:/opt/lampp/htdocs/dd/laravel# php artisan db:seed

Here, Is my UserTableSeeder.php & DatabaseSeeder.php Page

UserTableSeeder.php

<?php
use IlluminateDatabaseSeeder;
use IlluminateDatabaseEloquentModel;

class UserTableSeeder extends Seeder
{    
    public function run()
    {
        DB::table('users')->delete();
        User::create(array(
        'name'     => 'Chris Sevilleja',
        'username' => 'sevilayha',
        'email'    => 'chris@scotch.io',
        'password' => Hash::make('awesome'),
        ));
    }    
}

DatabaseSeeder.php

<?php

use IlluminateDatabaseSeeder;
use IlluminateDatabaseEloquentModel;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Eloquent::unguard();
        $this->call('UserTableSeeder');
    }
}

I'm Referring This Link To Design & Develop Login Page. Please Help me to resolve this issue. Thanks.

 Answers

51

Perform a composer update, then composer dump-autoload.

If the above doesn't solve the problem, change the classmap in your composer.json file such that it contains the project-relative path to your php files:

"autoload-dev": {
    "classmap": [
        "tests/TestCase.php",
        "database/seeds/UserTableSeeder.php" //include the file with its path here
    ]
}, /** ... */

and soon after, perform a composer dump-autoload, and it should work now like a breeze!

Edit by @JMSamudio

If composer dump-autoload is not found, just enable this option composer config -g -- disable-tls true.

Wednesday, March 31, 2021
 
BetaRide
answered 7 Months ago
89

Migration files must match the pattern *_*.php, or else they won't be found. Since users.php does not match this pattern (it has no underscore), this file will not be found by the migrator.

Ideally, you should be creating your migration files using artisan:

php artisan make:migration create_users_table

This will create the file with the appropriate name, which you can then edit to flesh out your migration. The name will also include the timestamp, to help the migrator determine the order of migrations.

You can also use the --create or --table switches to add a little bit more boilerplate to help get you started:

php artisan make:migration create_users_table --create=users

The documentation on migrations can be found here.

Saturday, May 29, 2021
 
Avicinnian
answered 5 Months ago
100

In PHP the use statement is more of an alias than import. So since the ClassesTableSeeder class isn't in a defined namespace, you don't need to import the DB class. As a result you can remove use DB entirely.

Saturday, May 29, 2021
 
ioleo
answered 5 Months ago
37

it turns out that i add a library to composer and added its service provider and alias to config/app.php like so:

'providers'       => [
 ..
    ClockworkSupportLaravelClockworkServiceProvider::class,

'aliases'         => [ 
..
    'Clockwork'        => ClockworkSupportLaravelFacade::class,

but then later on removed that library from composer (b/c i stopped using it) and forgot to update the service provider.

Updating the service provider solved the problem.

Bonus

I got the same problem again from one of my engineers working on a Pull Request that has like 100 commits in it (it's a topic branch.. please don't judge).

He affirmed that all the libraries are used.

So what I did is that I simply ran a git diff on two specific files only amongst that large range: config/app.php and composer.json like so:

Composer.json

$ git diff 96d397a bce2052 composer.json
diff --git a/composer.json b/composer.json
index 4c16f388..d780ec01 100644
--- a/composer.json
+++ b/composer.json
@@ -4,6 +4,12 @@
     "keywords": ["framework", "laravel"],
     "license": "MIT",
     "type": "project",
+    "repositories": [
+        {
+            "type": "vcs",
+            "url":  "https://github.com/abbood/translation"
+        }
+    ],
     "require": {
         "php": ">=5.5.9",
         "laravel/framework": "5.3.*",
@@ -26,7 +32,9 @@
         "aloha/twilio": "^2.1",
         "laravel/socialite": "^2.0",
         "barryvdh/laravel-dompdf": "^0.8.0",
-        "mockery/mockery": "1.0"
+        "mockery/mockery": "1.0",
+        "maxmind-db/reader": "~1.0",
+        "waavi/translation": "dev-extractGenCode"
     },
     "require-dev": {
         "symfony/dom-crawler": "~3.1",
@@ -35,6 +43,7 @@
         "phpunit/phpunit": "~5.0",
         "phpspec/phpspec": "~2.1",
         "johnkary/phpunit-speedtrap": "^1.0",
+        "orangehill/iseed": "2.2",
         "barryvdh/laravel-ide-helper": "^2.4"
     },
     "autoload": {

config/app.php

git diff 96d397a bce2052 config/app.php
diff --git a/config/app.php b/config/app.php
index 5025f79b..28e34794 100644
--- a/config/app.php
+++ b/config/app.php
@@ -10,8 +10,8 @@ return [
     | the framework needs to place the application's version in a notification
     | or any other location as required by the application or its packages.
     */
+    'version' => '1.3.57',

-    'version' => '1.3.46',

     'env' => env('APP_ENV', 'production'),

@@ -115,6 +115,17 @@ return [
     /*those options are overriden in bootstrap/app for info.log and error.log*/
     'log'             => 'daily',

+    /*
+    |--------------------------------------------------------------------------
+    | MaxMind mmdb Path
+    |--------------------------------------------------------------------------
+    |
+    | Here you specify the path to MaxMind GeoLite2-City.mmdb
+    |
+    |
+    */
+    'maxmindDB'             => env('APP_MAX_MIND_MMDB', "./maxmind/GeoLite2-City.mmdb"),
+
     /*
     |--------------------------------------------------------------------------
     | Autoloaded Service Providers
@@ -149,7 +160,6 @@ return [
         IlluminateRedisRedisServiceProvider::class,
         IlluminateAuthPasswordsPasswordResetServiceProvider::class,
         IlluminateSessionSessionServiceProvider::class,
-        IlluminateTranslationTranslationServiceProvider::class,
         IlluminateValidationValidationServiceProvider::class,
         IlluminateViewViewServiceProvider::class,

@@ -180,7 +190,10 @@ return [
         DavibennunLaravelPushNotificationLaravelPushNotificationServiceProvider::class,
         AlohaTwilioSupportLaravelServiceProvider::class,
         LaravelSocialiteSocialiteServiceProvider::class,
+        OrangehillIseedIseedServiceProvider::class,
         BarryvdhDomPDFServiceProvider::class,
+        WaaviTranslationTranslationServiceProvider::class,
+
     ],
     /*
     |--------------------------------------------------------------------------
@@ -239,6 +252,8 @@ return [
         'Raven'            => JenssegersRavenFacadesRaven::class,
         'Socialite'        => LaravelSocialiteFacadesSocialite::class,
         'PDF'              => BarryvdhDomPDFFacade::class,
+        'UriLocalizer'     => WaaviTranslationFacadesUriLocalizer::class,
+        'TranslationCache' => WaaviTranslationFacadesTranslationCache::class,
     ],

 ];

so the problem was clear: basically we're including "orangehill/iseed": "2.2", as a require-dev requirement, but not checking if the env is dev when we register it as a service provider.. so it blew up.

so this fixed it inside of app/Providers/AppServiceProvider.php:

namespace AppProviders;


use IlluminateSupportServiceProvider;

class AppServiceProvider extends ServiceProvider
{


    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $env = config('app.env');



        if ($env === 'local' || $env === 'testing') {
            .. dev only libraries
            $this->app->register(OrangehillIseedIseedServiceProvider::class);
        }
    }


}

bonus 2

sometimes you have to remove the entire bootstrap directory

rm -rf bootstrap

then run

composer dump-autoload

but laravel won't work after that, so you must git revert the change of deleting all of bootstrap (which should be in your git repo anyways).. and you're golden after that

enter image description here

Saturday, May 29, 2021
 
Easen
answered 5 Months ago
65

You need to put SongsTableSeeder into file SongsTableSeeder.php in the same directory where you have your DatabaseSeeder.php file.

And you need to run in your console:

composer dump-autoload

to generate new class map and then run:

php artisan db:seed

I've just tested it. It is working without a problem in Laravel 5

Sunday, June 27, 2021
 
mattltm
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :