Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type declaration in Illuminate\Database\Eloquent\Factories\Factory::createMany #38318

Closed
patryk-k opened this issue Aug 10, 2021 · 1 comment · Fixed by #38319
Closed
Labels

Comments

@patryk-k
Copy link

  • Laravel Version: 8.53.1
  • PHP Version: 8.0.8
  • Database Driver & Version: MySQL 8.0.25

Description:

createMany function of Illuminate\Database\Eloquent\Factories\Factory accepts any iterable variable as its first argument. It then tries to pass it to array_map which accepts only arrays.

  /**
   * Create a collection of models and persist them to the database.
   *
   * @param  iterable  $records
   * @return \Illuminate\Database\Eloquent\Collection
   */
  public function createMany(iterable $records)
  {
      return new EloquentCollection(
          array_map(function ($record) {
              return $this->state($record)->create();
          }, $records)
      );
  }

Steps To Reproduce:

$modelWithFactory::factory()->createMany(collect([['foo' => 'bar'],['foo' => 'baz']]));

The model and factory is irrelevant, the code will produce the following PHP error before getting anywhere regardless

array_map(): Argument #2 ($array) must be of type array, Illuminate\Support\Collection given

@driesvints
Copy link
Member

Thank you. I've sent in a PR for this: #38319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants