{"id":28549001,"url":"https://github.com/stydenet/factory","last_synced_at":"2025-08-02T07:41:38.746Z","repository":{"id":57060756,"uuid":"90023664","full_name":"StydeNet/factory","owner":"StydeNet","description":"Generate and build model factories for Laravel using classes and methods instead of closures","archived":false,"fork":false,"pushed_at":"2018-01-17T11:32:31.000Z","size":7,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-04T04:38:05.834Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StydeNet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-02T11:04:19.000Z","updated_at":"2018-05-01T17:33:56.000Z","dependencies_parsed_at":"2022-08-24T14:53:41.390Z","dependency_job_id":null,"html_url":"https://github.com/StydeNet/factory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StydeNet/factory","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StydeNet%2Ffactory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StydeNet%2Ffactory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StydeNet%2Ffactory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StydeNet%2Ffactory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StydeNet","download_url":"https://codeload.github.com/StydeNet/factory/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StydeNet%2Ffactory/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268348786,"owners_count":24236306,"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-08-02T02:00:12.353Z","response_time":74,"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":[],"created_at":"2025-06-10T01:35:26.266Z","updated_at":"2025-08-02T07:41:38.697Z","avatar_url":"https://github.com/StydeNet.png","language":"PHP","readme":"# Stydnet Factory Package\n\nThis packages allows you to build model factories\n for Laravel 5.4 using classes and methods instead of closures.\n \n## How to install\n\nInstall by running `composer require styde/factory:\"dev-master\" --dev`\n or adding `\"styde/factory\": \"dev-master\"` to the dev dependencies (`require-dev`) in the project's composer.json file\n  and then running composer update. \n\nThen create a \"factory-classes\" directory inside \"database\"\n and add the following to the \"autoload-dev\" section in your composer.json file:\n\n```\n      \"autoload-dev\": {\n          \"classmap\": [\n              \"database/factory-classes\",\n```\n\nAnd then execute `composer dump-autoload` in the console.\n \n**Note**: you can put the factory classes anywhere you want \n and of course you can also use PSR-4 if you want to.\n \n**Warning**: Laravel loads the database/factories/ multiple times during the test cycle.\n This will cause a conflict since you cannot override classes. So please don't put\n  the factory classes in the database/factories directory, unless you are completely sure you are not using the `factory` helper.\n  \n## Creating Factory Classes:\n\nThe factory classes have the following structure:\n\n```\n\u003c?php\n\nclass UserFactory extends Styde\\Factory\\Factory\n{\n    protected $model = 'App\\User';\n\n    public function data()\n    {\n        return [\n            /***/\n        ];\n    }\n}\n```\n\nYou can name the factory class whatever you like,\nbut you need to extend `Styde\\Factory\\Factory`\n\nYou also need to define the `$model` property\nand assign it the name of the model you want to create, (example: `App\\User`). \n\nAnd you need to add a `data()` method that will return\n an array with the default attributes for this model factory:\n \n Example:\n \n```\n     public function data()\n     {\n         return [\n             'first_name' =\u003e $this-\u003efirstName,\n             'last_name' =\u003e $this-\u003elastName,\n             'username' =\u003e $this-\u003eunique()-\u003euserName,\n             'email' =\u003e $this-\u003eunique()-\u003esafeEmail,\n             'remember_token' =\u003e str_random(10),\n         ];\n     }\n```\n  \nNotice in the case `$this-\u003e` is a proxy of `$this-\u003efaker-\u003e`\n\n### States:\n\nSince we are using classes now, states become simple methods inside the factory class:\n\n```\n    public function stateDelinquent()\n    {\n        return ['account_status' =\u003e 'delinquent'];\n    }\n```\n\nNote these methods need to be prefixed with the \"state\" \n and need to return the corresponding attributes.\n \n### Usage:\n\nWith factory classe **you won't use the factory helper**, instead you can write this:\n\n`UserFactory::create()` in order to create a new user and register it in the database.\n\n#### Other examples:\n\n* `UserFactory::make()` creates a new user without persisting it in the database.\n\n* `UserFactory::times(3)-\u003ecreate()` creates 3 users and persist them in the database.\n\n* `UserFactory::delinquent()-\u003ecreate()` creates a user with delinquent status (following the previous example about states).\n\n**This package is in development:** more tests, features and a stable version will be added later.\n\nIf you want to collaborate please send a pull request or report an issue here in GitHub.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstydenet%2Ffactory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstydenet%2Ffactory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstydenet%2Ffactory/lists"}