Level 102
You class is wrong
factory(Category::class, 5)->make();
And laravel 8 has changed the way factory works https://laravel.com/docs/8.x/database-testing#using-factories
Category::factory()->count(5)->make();
Summer Sale! All accounts are 50% off this week.
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();
}
}
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.