{"id":33203168,"url":"https://github.com/guidocella/eloquent-populator","last_synced_at":"2026-04-02T22:41:10.638Z","repository":{"id":62513276,"uuid":"76668572","full_name":"guidocella/eloquent-populator","owner":"guidocella","description":"Guess attributes for Laravel model factories","archived":false,"fork":false,"pushed_at":"2025-02-25T11:10:37.000Z","size":155,"stargazers_count":75,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-19T23:59:10.791Z","etag":null,"topics":["eloquent","faker","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guidocella.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-16T16:30:15.000Z","updated_at":"2025-03-13T18:40:44.000Z","dependencies_parsed_at":"2024-06-19T05:31:53.466Z","dependency_job_id":"f2398c88-7e8a-47a9-b68f-1eec5caae575","html_url":"https://github.com/guidocella/eloquent-populator","commit_stats":{"total_commits":111,"total_committers":2,"mean_commits":55.5,"dds":0.09009009009009006,"last_synced_commit":"a084918915118805552e7100e33afa7233ebee13"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/guidocella/eloquent-populator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidocella%2Feloquent-populator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidocella%2Feloquent-populator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidocella%2Feloquent-populator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidocella%2Feloquent-populator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guidocella","download_url":"https://codeload.github.com/guidocella/eloquent-populator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guidocella%2Feloquent-populator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284813088,"owners_count":27067232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","faker","laravel","php"],"created_at":"2025-11-16T09:00:32.855Z","updated_at":"2025-11-17T03:00:52.406Z","avatar_url":"https://github.com/guidocella.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Database/Eloquent/Models"],"readme":"# Eloquent Populator\n\nThis package provides default attributes for Laravel model factories by guessing the best [Faker](https://github.com/fakerphp/Faker) formatters from columns' names and types.\nFor example, if a column is called `first_name`, it will use `$faker-\u003efirstName()`. If unable to guess by the column's name, it will guess the formatter by the column's type; for example, it will use `$faker-\u003etext()` for a `VARCHAR` column, or a Carbon instance for a `TIMESTAMP`. Models of `BelongsTo` relationships that have been defined are created as well.\nFurthermore, if you use the [Multilingual](https://github.com/guidocella/laravel-multilingual) package, for translatable attributes Populator will generate arrays with a different value for each configured locale.\n\nCompared to packages that generate factories once, you generally don't have to update your factories as you change their table definitions and they will be very small.\n\n## Installation\n\nInstall the package with Composer:\n\n```sh\ncomposer require --dev guidocella/eloquent-populator\n```\n\n## Model factory integration\n\nCall `Populator::guessFormatters($this-\u003emodelName())` in your factories' `definition` methods to get an array with the guessed formatters. You may merge these with custom attributes whose guessed formatter isn't accurate.\n\n```php\nuse GuidoCella\\EloquentPopulator\\Populator;\n\n...\n\npublic function definition(): array\n{\n    return [...Populator::guessFormatters($this-\u003emodelName()), ...[\n        'avatar' =\u003e $this-\u003efaker-\u003eimageUrl()\n    ]];\n}\n```\n\nIf you execute `php artisan stub:publish`, you can include the call to Populator in `factory.stub` so that `php artisan make:factory` will add it.\n\nAfter guessing a model's formatters once, they are cached in a static property even across different tests.\n\n## Seeding\n\nBefore seeding your database you'll want to call `setSeeding()`.\n\n```php\npublic function run()\n{\n    Populator::setSeeding();\n```\n\nIts effect is that nullable columns will have a 50% chance of being set to `null` or to the guessed formatter.\n\n## Testing\n\nIf `setSeeding()` wasn't called nullable columns will always be set to their guessed formatter. The idea is to simplify tests such as this:\n\n```php\npublic function testSubmitWithoutName() {\n    $user = User::factory()-\u003emake(['name' =\u003e null]);\n    // test that submitting a form with $user's attributes causes an error\n}\n\npublic function testSubmitWithCorrectName() {\n    $user = User::factory()-\u003emake();\n    // no need to specify the correct formatter for name since it can't be null\n    // test that submitting a form with $user's attributes is succesful\n}\n```\n\nOn the other hand, seeding the database with `null` attributes lets you notice `Trying to get property of non-object` errors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidocella%2Feloquent-populator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguidocella%2Feloquent-populator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguidocella%2Feloquent-populator/lists"}