0

I'm trying to learn about laravel. I'm not busy with seeding put I keep getting the following error:

[ReflectionException]
Class UserTableSeeder does not exist

What have I done:

User class

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
    use Authenticatable, CanResetPassword;

    /**
     * The database table used by the model.
     *
     * @var string
    */
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'username', 'email', 'password'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
     protected $hidden = ['password', 'remember_token'];
}

CreateUserTable migration:

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('username');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}

UserTableSeeder

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class UserTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB:table('users')->delete();
        User::create(array(
            'name'      => 'Graham Neal',
            'username'  => 'Graham',
            'email'     => 'grahamneal1991@gmail.com',
            'password'  => Hash::make('0258456'),
        ));
    }
}

DatabaseSeeder

    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::class);
        $this->call('UserTableSeeder');

        Model::reguard();
    }
}

in the database seeder i've tried the following:

$this->call('UserTableSeeder');
$this->call('UserTableSeeder::User');
$this->call('App/UserTableSeeder');
$this->call('App/UserTableSeeder::User');

I know it can't find the class but I am left in the dark about finding out why? I've searched google and found other places where it went wrong with other people but I don't seem to have the same mistakes. Hope this isn't a really stupid question.

EDIT*

If i do composer dump-autoload I get the above error and the following exception trace:

  [RuntimeException]
  Could not scan for classes inside "user" which does not appear to be a file
   nor a folder

This error was given after I added the class manually to the composer.json file.

Now if I'm trying to php artisan db:seed I get another error:

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined function table()
Graham
  • 1,850
  • 4
  • 21
  • 41

2 Answers2

0

First, make sure your seeder is in the database/seed/ directory.

Then, use composer's dump-autoload

0

Make sure your file is named correctly. And it should be in the same folder as DatabaseSeeder's.

Hudson Pereira
  • 1,066
  • 8
  • 13
  • The file names are the same and UserTableSeeder and DatabaseSeeder are both in database/seeds/ folder – Graham Jul 07 '15 at 18:36