Laravel seeder gives error. Class not found

samhu kiklsk picture samhu kiklsk · Oct 13, 2014 · Viewed 26.6k times · Source

I'm a newbie in Laravel and and I'm teaching myself how to authenticate from a login table. I have migrated and created the table. Now, I'm trying to seed the data into the login table, but the command prompt is continuously giving me error, which says Fatal Error, class login not found and I have no idea what i have missed. So can anyone please help me. Here is the code that i have, and yes I'm using Laravel 4.3

<?php
class loginTableSeeder extends Seeder
{
    public function run()
    {
        DB::table('login')->delete();
        login::create(array(
            'username'  =>  'sanju',
            'password'  =>  Hash::make('sanju')
            ));
    }
}


?> 

Answer

Marcin Nabiałek picture Marcin Nabiałek · Oct 13, 2014

EDIT

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;

in the next line after <?php

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

<?php

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

EARLIER ANSWER

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:

$this->call('LoginTableSeeder');

You should put into database/seeds file LoginTableSeeder.php with capital letter at the beginning.

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
    }
}

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.