Last active
September 13, 2020 09:30
-
-
Save agungsugiarto/7a5e1aa8c0acd794601a0cf0fd032e16 to your computer and use it in GitHub Desktop.
Helper factory to easy create database seeder for CodeIgniter4.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (! function_exists('factory')) { | |
/** | |
* Create a factory seeder. | |
* | |
* @param Model|object|string $model Instance or name of the model | |
* @param int|null $count Create factory | |
* @param array|null $formatters Difine faker factory | |
* @param array|null $overrides Overriding data to pass to Fabricator::setOverrides() | |
* @return object|array | |
*/ | |
function factory($model, $count = null, ?array $formatters = null, ?array $overrides = null) | |
{ | |
$fabricator = new \CodeIgniter\Test\Fabricator($model, $formatters); | |
if (! is_null($overrides)) { | |
$fabricator->setOverrides($overrides); | |
} | |
return $fabricator->create($count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment