Laravel 5.2: Unable to locate factory with name [default]

paranoid picture paranoid · Apr 5, 2016 · Viewed 68.6k times · Source

I want to seed database when I use this

 public function run()
{
    $users = factory(app\User::class, 3)->create();
}

Add three user in database but when I use this

 public function run()
{
    $Comment= factory(app\Comment::class, 3)->create();
}

Show me error

[InvalidArgumentException]
Unable to locate factory with name [default] [app\Comment].

Answer

Ayeni TonyOpe picture Ayeni TonyOpe · Jan 21, 2020

Some times it could be due to importing the wrong TestCase

use PHPUnit\Framework\TestCase; [WRONG: and throws this error]


use Tests\TestCase; [CORRECT]