Class "UserTableSeeder" does not exist - Laravel 5.0 [php artisan db: seed]

Im brand new to laravel and im trying to learn to do a few basic things, so please tell me. So I try to use the basic php artisan db: seed after migrating my database, but it continues to return a header error in cmd - [ReflectionException] Class "UserTableSeeder" does not exist

Things i tried

  • Change the namespace in the namespace UserTableSeeder.php 'Database \ seed;' and 'use database \ seed \ UserTableSeeder;' in the file "DatabaseSeeder.php"

Migration Listed Below

<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function(Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password', 60); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('users'); } } 

Below is UserTableSeeder.php

 <?php use App\User; use Illuminate\Database\Seeder; class UserTableSeeder extends Seeder { public function run() { DB::table('users')->delete(); User::create(['email' => ' foo@bar.com ']); } } 

Below is DatabaseSeeder.php

 <?php use Illuminate\Database\Seeder; use Illuminate\Database\Eloquent\Model; class DatabaseSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $this->call('UserTableSeeder'); } } 
+5
source share
2 answers

Run composer dumpautoload after creating the files in the database / folder.

Why?

Check the startup section of composer.json and you will see that the database/ folder is loaded using "classmap" ( source ):

 "autoload": { "classmap": [ "database" ], "psr-4": { "App\\": "app/" } }, 

Composer docs describes classmap as:

All links to classmap are combined during installation / upgrade into an array with one key =>, which can be found in the generated file seller / composer / autoload_classmap.php. This map is built by scanning for classes in all .php and .inc files in the specified directories / files .

You can use classmap generation support to determine autoload for all libraries that do not match PSR-0/4. To configure this, you specify all directories or files to search for classes.

Accent added. You need to run the composer dumpautoload to generate a new class map every time you add a file to database/ , otherwise it will not be automatically loaded.

The app/ folder uses the PSR-4 standard to convert the fully qualified class name to the file system path. That is why you do not need dumpautoload after adding files there.

+23
source

Try to change

  $this->call('UserTableSeeder'); 

to

  $this->call(UserTableSeeder::class); 

and try to run

  composer dump-autoload 
+8
source

Source: https://habr.com/ru/post/1245720/


All Articles