Im new to Laravel and am trying to grasp the seeding and the factory. I basically want to have main categories which will have null value as the parent_id field, and that will be the indicator that they are the main categories, then I want to have sub categories, which will have the id of the main categories as their parent_id. However I get thrown Maximum retries of 10000 reached without finding a unique value:
public function definition(): array
{
Category::factory(10)->create(['parent_id' => null, 'name' => $this->faker->unique()->jobTitle])
->each(function ($category){
Category::factory(rand(0, 5))->create(['parent_id' => $category->id, 'name' => $this->faker->unique()->jobTitle]);
});
return [];
}
I am not sure what causes this error as I create 10 Categories and then I create 1-5 sub-categories. In total I can have a maximum of 60 entries if it creates 5 sub categories for each category. I have also removed the ->unique() from the subcategories, so that only 10 Categories are unique, but to no avail.
EDIT: When I remove the unique from both I get the error:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)
This is a new application and I have only 3 Models: Category, Listing and User, Im not sure whats triggering this, as my memory_limit is set to the max setting in Plesk -> 128M