fzaninotto/Faker

Guard raised against custom insert without factory in database seeder

wolfiton opened this issue · 0 comments

Summary

Guard raised gainst custom insert without factory

Versions

Laravel 7

Version
PHP x.y.z
fzaninotto/faker x.y.z

Self-enclosed code snippet for reproduction

$categories = ['Hardware', 'Software', 'Planning', 'Tools'];
        foreach ($categories as $category) {
            App\Category::create([
                'name' => $category,
                'slug' => Str::slug($category),
            ]);
        }

Expected output

Inserting the category name and slug

Actual output

 Unable to locate factory for [App\Category].

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:273
    269|      */
    270|     protected function getRawAttributes(array $attributes = [])
    271|     {
    272|         if (! isset($this->definitions[$this->class])) {
  > 273|             throw new InvalidArgumentException("Unable to locate factory for [{$this->class}].");
    274|         }
    275| 
    276|         $definition = call_user_func(
    277|             $this->definitions[$this->class],