Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Doc: Add distinct values to a category table in Laravel 7 using factories (no documentation for this common case) #2015

Open
wolfiton opened this issue Jun 21, 2020 · 0 comments

Comments

@wolfiton
Copy link

Summary

Trying to add distinct values to a category table in Laravel 7 using factories

Self-enclosed code snippet for reproduction

<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Category;
use Illuminate\Support\Str;
use Faker\Generator as Faker;

$categories = ['Hardware', 'Software', 'Planning', 'Tools'];

foreach ($categories as $categoryName) {
    factory(Category::class)->create([
        'name' => $categoryName,
        'slug' => Str::slug($categoryName),
    ]);
}
//Seeder
factory('App\Category', [detect categories array count])->create();

Expected output

id:1 name:Hardware'

Actual output

require(/home/dan/Codes/laravel/jobportal/database/factories/CategoryFactory.php): failed to open stream: Too many open files

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php:220
    216|         $factory = $this;
    217| 
    218|         if (is_dir($path)) {
    219|             foreach (Finder::create()->files()->name('*.php')->in($path) as $file) {
  > 220|                 require $file->getRealPath();
    221|             }
    222|         }
    223| 
    224|         return $factory;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant