Fake data generator using facker

Posted 1 month ago by mousumi_mou

For the first time I tried to generate fake data using facker. But while I wrote artisan command db:seed , there showed an error. I can't find out the problem. Can anyone help me please?

D:\laragon\www\to-do

λ php artisan db:seed

Seeding: TodosTableSeeder

InvalidArgumentException : Unable to locate factory with name [default] [App\Todo].

at D:\laragon\www\todo\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:269

265| */ 266| protected function getRawAttributes(array $attributes = []) 267| { 268| if (! isset($this->definitions[$this->class][$this->name])) {

269| throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}[{$this->cl 270| } 271| 272| $definition = call_user_func( 273| $this->definitions[$this->class][$this->name],

Exception trace:

1 Illuminate\Database\Eloquent\FactoryBuilder::getRawAttributes([])

D:\laragon\www\to-do\vendor\laravel\framework\src\Illuminate\Database\Eloquent\FactoryBuilder.php:292

2 Illuminate\Database\Eloquent\FactoryBuilder::Illuminate\Database\Eloquent{closure}() D:\laragon\www\todo\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\GuardsAttributes.php:116

This is my database table:


public function up()
    {
        Schema::create('todos', function (Blueprint $table) {
            $table->increments('id');
            $table->string('todo');
            $table->boolean('completed')->default(0);
            $table->timestamps();
        });
    }

This is userFactory code:


$factory->define(App\User::class, function (Faker $faker) {
    return[
        'todo' => $faker->sentance(10)
    ];
});

This is TodosTableSeeder code:


class TodosTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(App\Todo::class, 7)->create();
    }
}

This is DatabaseSeeder code:



class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // $this->call(UsersTableSeeder::class);
        $this->call(TodosTableSeeder::class);
    }
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.