Skip to content

Commit

Permalink
allow quiet creation
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 31, 2021
1 parent 1b819bf commit e9cd94c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ public function createOne($attributes = [])
return $this->count(null)->create($attributes);
}

/**
* Create a single model and persist it to the database.
*
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
*/
public function createOneQuietly($attributes = [])
{
return $this->count(null)->createQuietly($attributes);
}

/**
* Create a collection of models and persist them to the database.
*
Expand All @@ -217,6 +228,19 @@ public function createMany(iterable $records)
);
}

/**
* Create a collection of models and persist them to the database.
*
* @param iterable $records
* @return \Illuminate\Database\Eloquent\Collection
*/
public function createManyQuietly(iterable $records)
{
return Model::withoutEvents(function () use ($records) {
return $this->createMany($records);
});
}

/**
* Create a collection of models and persist them to the database.
*
Expand Down Expand Up @@ -245,6 +269,20 @@ public function create($attributes = [], ?Model $parent = null)
return $results;
}

/**
* Create a collection of models and persist them to the database.
*
* @param array $attributes
* @param \Illuminate\Database\Eloquent\Model|null $parent
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
*/
public function createQuietly($attributes = [], ?Model $parent = null)
{
return Model::withoutEvents(function () use ($attributes, $parent) {
return $this->create($attributes, $parent);
});
}

/**
* Create a callback that persists a model in the database when invoked.
*
Expand Down

0 comments on commit e9cd94c

Please sign in to comment.