Summer Sale! All accounts are 50% off this week.

artisticre's avatar

CategoriesTableSeeder Error

Not sure why I am getting this error.

Error

Call to undefined function Database\Seeders\factory()

  at C:\wamp64\www\haylee\database\seeders\CategoriesTableSeeder.php:24
     20▕             'parent_id'     =>  null,
     21▕             'menu'          =>  0,
     22▕         ]);
     23▕
  ➜  24▕         factory(App\Models\Category::class, 5)->make();
     25▕     }
     26▕ }

  1   C:\wamp64\www\haylee\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:37
      Database\Seeders\CategoriesTableSeeder::run()

  2   C:\wamp64\www\haylee\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:37
      call_user_func_array([])

Seeder

<?php

namespace Database\Seeders;
use App\Models\Category;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;

class CategoriesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Category::create([
            'name'          =>  'Root',
            'description'   =>  'This is the root category, don\'t delete this one',
            'parent_id'     =>  null,
            'menu'          =>  0,
        ]);

        factory(App\Models\Category::class, 5)->make();
    }
}
0 likes
2 replies
ismaile's avatar
ismaile
Best Answer
Level 30

There have been some changes in Laravel 8 regarding factories. You no longer can use the factory helper unless you use a legacy package:

composer require laravel/legacy-factories

This should solve your issue but I'd recommend upgrading to the new way of handling factories.

Here is the relevant documentation: https://laravel.com/docs/8.x/upgrade#model-factories

Please or to participate in this conversation.