Skip to content
Advertisement

Laravel seeder gives error. Class not found

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')
            ));
    }
}


?> 

Advertisement

Answer

You need to create an Eloquent model for that table in order to use Login::create(). You can do that with a simple artisan command:

$ php artisan generate:model Login

This will generate a new Eloquent model in app/models directory which should look like this.

class Login extends Eloquent {

    protected $fillable = [];
    protected $table = 'login';

}

Your code should work after that. If it still doesn’t make sure you run composer dump-autoload.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement