Laravel seeder gives error. Class not found

Asked
Active3 hr before
Viewed126 times

7 Answers

giveserrorlaravel
90%

you need to import Seeder with use at the beginning of file and again class name should start with capital letter.,Now you should run composer dump-autoload and now when you run php artisan db:seed it will work fine.,You should put into database/seeds file LoginTableSeeder.php with capital letter at the beginning.,Your code should work after that. If it still doesn't make sure you run composer dump-autoload.

Now I see, the problem is with your login class (with earlier question formatting the exact error was illegible). You should look again what's the name of file where you have login class and what's the name of class. The convention is that the file should have name Login.php (with capital letter) and the name of class also should be Login (with capital letter). You should also check in what namespace is your Login class. If it is defined in in App namespace, you should add to your LoginTableSeeder:

use App\ Login;

so basically the beginning of your file should look like this:

< ? php

use App\ Login;
use Illuminate\ Database\ Seeder;

In database/seeds/DatabaseSeeder.php you should run Login seeder like this:

$this - > call('LoginTableSeeder');

Now, your file LoginTableSeeder.php file should look like this:

< ? php

use Illuminate\ Database\ Seeder;

class LoginTableSeeder extends Seeder {
   public
   function run() {

      // your code goes here
   }
}
load more v
88%

You didn't explained what the exact error is (probably the error is for Seeder class) but:,In database/seeds/DatabaseSeeder.php you should run Login seeder like this:,You should put into database/seeds file LoginTableSeeder.php with capital letter at the beginning.,you need to import Seeder with use at the beginning of file and again class name should start with capital letter.

Now I see, the problem is with your login class (with earlier question formatting the exact error was illegible). You should look again what's the name of file where you have login class and what's the name of class. The convention is that the file should have name Login.php (with capital letter) and the name of class also should be Login (with capital letter). You should also check in what namespace is your Login class. If it is defined in in App namespace, you should add to your LoginTableSeeder:

use App\ Login;
load more v
72%

use Illuminate\ Database\ Seeder;
65%

To generate a seeder, execute the make:seeder Artisan command. All seeders generated by the framework will be placed in the database/seeders directory:,Within the DatabaseSeeder class, you may use the call method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes too large. The call method accepts an array of seeder classes that should be executed:,{tip} Mass assignment protection is automatically disabled during database seeding.,As an example, let's modify the default DatabaseSeeder class and add a database insert statement to the run method:

To generate a seeder, execute the make:seeder Artisan command. All seeders generated by the framework will be placed in the database/seeders directory:

php artisan make: seeder UserSeeder
load more v
75%

Today I am getting this error when I am trying to refresh seed with php artisan migrate:refresh –seed command. Database Seeder class is called another seeder class with $this->call(CmsPagesSeeder::class); But geeting error Target class [CmsPagesSeeder] does not exist.,Finally I have apply follwing solution and now working fine with command php artisan migrate:refresh –seed or php artisan db:seed or php artisan db:seed –class=CmsPagesSeeder, Laravel 8 Target class [TableSeeder] does not exist ,Open your others seeders file and add namespace Database\Seeders; to all seeders class.

namespace Database\ Seeders;
load more v
40%

As soon, I am typing php artisan db:seed command.,I'm getting Error Like:, Error ReflectionException Class ClassName does... ,80792/error-reflectionexception-class-classname-exist-laravel

I'm getting Error Like:

[ReflectionException]
Class UserTableSeeder does not exist

UserTableSeeder.php

< ? php
use Illuminate\ Database\ Seeder;
use Illuminate\ Database\ Eloquent\ Model;

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 Illuminate\ Database\ Seeder;
use Illuminate\ Database\ Eloquent\ Model;

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

"Target class [Database\Seeders\AdminSeeder] does not exist.",What is Database Seeder in Laravel 6?,Laravel 7 Database Seeder Example,Laravel 8 Database Seeder Tutorial Example

< ? php namespace Database\ Seeders;
use Illuminate\ Database\ Seeder;
class DatabaseSeeder extends Seeder {
   /**     * Seed the application's database.     *     * @return void     */
   public
   function run() {
      $this - > call(AdminSeeder::class);
   }
}
load more v

Other "gives-error" queries related to "Laravel seeder gives error. Class not found"