[
  {
    "path": ".github/workflows/test.yml",
    "content": "name: Run tests\n\non:\n  push:\n  pull_request:\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n\n    strategy:\n      fail-fast: false\n      matrix:\n        php: [ 8.1, 8.2, 8.3, 8.4, 8.5 ]\n        laravel: [ 10.*, 11.*, 12.*, 13.* ]\n        dependency-version: [ prefer-lowest, prefer-stable ]\n        exclude:\n          - php: 8.1\n            laravel: 11.*\n          - php: 8.1\n            laravel: 12.*\n          - php: 8.1\n            laravel: 13.*\n          - php: 8.2\n            laravel: 13.*\n\n    name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}\n\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v1\n\n      - name: Setup PHP\n        uses: shivammathur/setup-php@v2\n        with:\n          php-version: ${{ matrix.php }}\n          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick\n          coverage: none\n\n      - name: Install dependencies\n        run: |\n          composer require \"laravel/framework:${{ matrix.laravel }}\" --no-interaction --no-update\n          composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction\n\n      - name: Execute tests\n        run: vendor/bin/phpunit"
  },
  {
    "path": ".gitignore",
    "content": "build\ncomposer.phar\ncomposer.lock\nvendor\n.php_cs.cache\n.phpunit.result.cache\n.phpunit.cache\n"
  },
  {
    "path": ".styleci.yml",
    "content": "preset: laravel"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing\n\nWe accept contributions via Pull Requests on [Github](https://github.com/makeable/laravel-production-seeding).\n\n\n## Pull Requests\n\n- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - see **fixing styles** section\n\n- **Add tests** - Your patch must include tests of the added functionality. See **Running tests** section\n\n- **Document any change in behaviour** - Make sure the `README.md` and  `CHANGELOG.md` are kept up-to-date.\n\n- **Create feature branches** - Don't ask us to pull from your master branch.\n\n\n## Fixing styles\n\n``` bash\n$ composer style\n```\n\n## Running Tests\n\n``` bash\n$ composer test\n```\n\n\n**Happy coding**!"
  },
  {
    "path": "LICENSE.md",
    "content": "Attribution-ShareAlike 4.0 International\n\n=======================================================================\n\nCreative Commons Corporation (\"Creative Commons\") is not a law firm and\ndoes not provide legal services or legal advice. Distribution of\nCreative Commons public licenses does not create a lawyer-client or\nother relationship. Creative Commons makes its licenses and related\ninformation available on an \"as-is\" basis. Creative Commons gives no\nwarranties regarding its licenses, any material licensed under their\nterms and conditions, or any related information. Creative Commons\ndisclaims all liability for damages resulting from their use to the\nfullest extent possible.\n\nUsing Creative Commons Public Licenses\n\nCreative Commons public licenses provide a standard set of terms and\nconditions that creators and other rights holders may use to share\noriginal works of authorship and other material subject to copyright\nand certain other rights specified in the public license below. The\nfollowing considerations are for informational purposes only, are not\nexhaustive, and do not form part of our licenses.\n\n     Considerations for licensors: Our public licenses are\n     intended for use by those authorized to give the public\n     permission to use material in ways otherwise restricted by\n     copyright and certain other rights. Our licenses are\n     irrevocable. Licensors should read and understand the terms\n     and conditions of the license they choose before applying it.\n     Licensors should also secure all rights necessary before\n     applying our licenses so that the public can reuse the\n     material as expected. Licensors should clearly mark any\n     material not subject to the license. This includes other CC-\n     licensed material, or material used under an exception or\n     limitation to copyright. More considerations for licensors:\n    wiki.creativecommons.org/Considerations_for_licensors\n\n     Considerations for the public: By using one of our public\n     licenses, a licensor grants the public permission to use the\n     licensed material under specified terms and conditions. If\n     the licensor's permission is not necessary for any reason--for\n     example, because of any applicable exception or limitation to\n     copyright--then that use is not regulated by the license. Our\n     licenses grant only permissions under copyright and certain\n     other rights that a licensor has authority to grant. Use of\n     the licensed material may still be restricted for other\n     reasons, including because others have copyright or other\n     rights in the material. A licensor may make special requests,\n     such as asking that all changes be marked or described.\n     Although not required by our licenses, you are encouraged to\n     respect those requests where reasonable. More_considerations\n     for the public:\n    wiki.creativecommons.org/Considerations_for_licensees\n\n=======================================================================\n\nCreative Commons Attribution-ShareAlike 4.0 International Public\nLicense\n\nBy exercising the Licensed Rights (defined below), You accept and agree\nto be bound by the terms and conditions of this Creative Commons\nAttribution-ShareAlike 4.0 International Public License (\"Public\nLicense\"). To the extent this Public License may be interpreted as a\ncontract, You are granted the Licensed Rights in consideration of Your\nacceptance of these terms and conditions, and the Licensor grants You\nsuch rights in consideration of benefits the Licensor receives from\nmaking the Licensed Material available under these terms and\nconditions.\n\n\nSection 1 -- Definitions.\n\n  a. Adapted Material means material subject to Copyright and Similar\n     Rights that is derived from or based upon the Licensed Material\n     and in which the Licensed Material is translated, altered,\n     arranged, transformed, or otherwise modified in a manner requiring\n     permission under the Copyright and Similar Rights held by the\n     Licensor. For purposes of this Public License, where the Licensed\n     Material is a musical work, performance, or sound recording,\n     Adapted Material is always produced where the Licensed Material is\n     synched in timed relation with a moving image.\n\n  b. Adapter's License means the license You apply to Your Copyright\n     and Similar Rights in Your contributions to Adapted Material in\n     accordance with the terms and conditions of this Public License.\n\n  c. BY-SA Compatible License means a license listed at\n     creativecommons.org/compatiblelicenses, approved by Creative\n     Commons as essentially the equivalent of this Public License.\n\n  d. Copyright and Similar Rights means copyright and/or similar rights\n     closely related to copyright including, without limitation,\n     performance, broadcast, sound recording, and Sui Generis Database\n     Rights, without regard to how the rights are labeled or\n     categorized. For purposes of this Public License, the rights\n     specified in Section 2(b)(1)-(2) are not Copyright and Similar\n     Rights.\n\n  e. Effective Technological Measures means those measures that, in the\n     absence of proper authority, may not be circumvented under laws\n     fulfilling obligations under Article 11 of the WIPO Copyright\n     Treaty adopted on December 20, 1996, and/or similar international\n     agreements.\n\n  f. Exceptions and Limitations means fair use, fair dealing, and/or\n     any other exception or limitation to Copyright and Similar Rights\n     that applies to Your use of the Licensed Material.\n\n  g. License Elements means the license attributes listed in the name\n     of a Creative Commons Public License. The License Elements of this\n     Public License are Attribution and ShareAlike.\n\n  h. Licensed Material means the artistic or literary work, database,\n     or other material to which the Licensor applied this Public\n     License.\n\n  i. Licensed Rights means the rights granted to You subject to the\n     terms and conditions of this Public License, which are limited to\n     all Copyright and Similar Rights that apply to Your use of the\n     Licensed Material and that the Licensor has authority to license.\n\n  j. Licensor means the individual(s) or entity(ies) granting rights\n     under this Public License.\n\n  k. Share means to provide material to the public by any means or\n     process that requires permission under the Licensed Rights, such\n     as reproduction, public display, public performance, distribution,\n     dissemination, communication, or importation, and to make material\n     available to the public including in ways that members of the\n     public may access the material from a place and at a time\n     individually chosen by them.\n\n  l. Sui Generis Database Rights means rights other than copyright\n     resulting from Directive 96/9/EC of the European Parliament and of\n     the Council of 11 March 1996 on the legal protection of databases,\n     as amended and/or succeeded, as well as other essentially\n     equivalent rights anywhere in the world.\n\n  m. You means the individual or entity exercising the Licensed Rights\n     under this Public License. Your has a corresponding meaning.\n\n\nSection 2 -- Scope.\n\n  a. License grant.\n\n       1. Subject to the terms and conditions of this Public License,\n          the Licensor hereby grants You a worldwide, royalty-free,\n          non-sublicensable, non-exclusive, irrevocable license to\n          exercise the Licensed Rights in the Licensed Material to:\n\n            a. reproduce and Share the Licensed Material, in whole or\n               in part; and\n\n            b. produce, reproduce, and Share Adapted Material.\n\n       2. Exceptions and Limitations. For the avoidance of doubt, where\n          Exceptions and Limitations apply to Your use, this Public\n          License does not apply, and You do not need to comply with\n          its terms and conditions.\n\n       3. Term. The term of this Public License is specified in Section\n          6(a).\n\n       4. Media and formats; technical modifications allowed. The\n          Licensor authorizes You to exercise the Licensed Rights in\n          all media and formats whether now known or hereafter created,\n          and to make technical modifications necessary to do so. The\n          Licensor waives and/or agrees not to assert any right or\n          authority to forbid You from making technical modifications\n          necessary to exercise the Licensed Rights, including\n          technical modifications necessary to circumvent Effective\n          Technological Measures. For purposes of this Public License,\n          simply making modifications authorized by this Section 2(a)\n          (4) never produces Adapted Material.\n\n       5. Downstream recipients.\n\n            a. Offer from the Licensor -- Licensed Material. Every\n               recipient of the Licensed Material automatically\n               receives an offer from the Licensor to exercise the\n               Licensed Rights under the terms and conditions of this\n               Public License.\n\n            b. Additional offer from the Licensor -- Adapted Material.\n               Every recipient of Adapted Material from You\n               automatically receives an offer from the Licensor to\n               exercise the Licensed Rights in the Adapted Material\n               under the conditions of the Adapter's License You apply.\n\n            c. No downstream restrictions. You may not offer or impose\n               any additional or different terms or conditions on, or\n               apply any Effective Technological Measures to, the\n               Licensed Material if doing so restricts exercise of the\n               Licensed Rights by any recipient of the Licensed\n               Material.\n\n       6. No endorsement. Nothing in this Public License constitutes or\n          may be construed as permission to assert or imply that You\n          are, or that Your use of the Licensed Material is, connected\n          with, or sponsored, endorsed, or granted official status by,\n          the Licensor or others designated to receive attribution as\n          provided in Section 3(a)(1)(A)(i).\n\n  b. Other rights.\n\n       1. Moral rights, such as the right of integrity, are not\n          licensed under this Public License, nor are publicity,\n          privacy, and/or other similar personality rights; however, to\n          the extent possible, the Licensor waives and/or agrees not to\n          assert any such rights held by the Licensor to the limited\n          extent necessary to allow You to exercise the Licensed\n          Rights, but not otherwise.\n\n       2. Patent and trademark rights are not licensed under this\n          Public License.\n\n       3. To the extent possible, the Licensor waives any right to\n          collect royalties from You for the exercise of the Licensed\n          Rights, whether directly or through a collecting society\n          under any voluntary or waivable statutory or compulsory\n          licensing scheme. In all other cases the Licensor expressly\n          reserves any right to collect such royalties.\n\n\nSection 3 -- License Conditions.\n\nYour exercise of the Licensed Rights is expressly made subject to the\nfollowing conditions.\n\n  a. Attribution.\n\n       1. If You Share the Licensed Material (including in modified\n          form), You must:\n\n            a. retain the following if it is supplied by the Licensor\n               with the Licensed Material:\n\n                 i. identification of the creator(s) of the Licensed\n                    Material and any others designated to receive\n                    attribution, in any reasonable manner requested by\n                    the Licensor (including by pseudonym if\n                    designated);\n\n                ii. a copyright notice;\n\n               iii. a notice that refers to this Public License;\n\n                iv. a notice that refers to the disclaimer of\n                    warranties;\n\n                 v. a URI or hyperlink to the Licensed Material to the\n                    extent reasonably practicable;\n\n            b. indicate if You modified the Licensed Material and\n               retain an indication of any previous modifications; and\n\n            c. indicate the Licensed Material is licensed under this\n               Public License, and include the text of, or the URI or\n               hyperlink to, this Public License.\n\n       2. You may satisfy the conditions in Section 3(a)(1) in any\n          reasonable manner based on the medium, means, and context in\n          which You Share the Licensed Material. For example, it may be\n          reasonable to satisfy the conditions by providing a URI or\n          hyperlink to a resource that includes the required\n          information.\n\n       3. If requested by the Licensor, You must remove any of the\n          information required by Section 3(a)(1)(A) to the extent\n          reasonably practicable.\n\n  b. ShareAlike.\n\n     In addition to the conditions in Section 3(a), if You Share\n     Adapted Material You produce, the following conditions also apply.\n\n       1. The Adapter's License You apply must be a Creative Commons\n          license with the same License Elements, this version or\n          later, or a BY-SA Compatible License.\n\n       2. You must include the text of, or the URI or hyperlink to, the\n          Adapter's License You apply. You may satisfy this condition\n          in any reasonable manner based on the medium, means, and\n          context in which You Share Adapted Material.\n\n       3. You may not offer or impose any additional or different terms\n          or conditions on, or apply any Effective Technological\n          Measures to, Adapted Material that restrict exercise of the\n          rights granted under the Adapter's License You apply.\n\n\nSection 4 -- Sui Generis Database Rights.\n\nWhere the Licensed Rights include Sui Generis Database Rights that\napply to Your use of the Licensed Material:\n\n  a. for the avoidance of doubt, Section 2(a)(1) grants You the right\n     to extract, reuse, reproduce, and Share all or a substantial\n     portion of the contents of the database;\n\n  b. if You include all or a substantial portion of the database\n     contents in a database in which You have Sui Generis Database\n     Rights, then the database in which You have Sui Generis Database\n     Rights (but not its individual contents) is Adapted Material,\n\n     including for purposes of Section 3(b); and\n  c. You must comply with the conditions in Section 3(a) if You Share\n     all or a substantial portion of the contents of the database.\n\nFor the avoidance of doubt, this Section 4 supplements and does not\nreplace Your obligations under this Public License where the Licensed\nRights include other Copyright and Similar Rights.\n\n\nSection 5 -- Disclaimer of Warranties and Limitation of Liability.\n\n  a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE\n     EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS\n     AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF\n     ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,\n     IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,\n     WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR\n     PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,\n     ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT\n     KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT\n     ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.\n\n  b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE\n     TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,\n     NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,\n     INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,\n     COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR\n     USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN\n     ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR\n     DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR\n     IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.\n\n  c. The disclaimer of warranties and limitation of liability provided\n     above shall be interpreted in a manner that, to the extent\n     possible, most closely approximates an absolute disclaimer and\n     waiver of all liability.\n\n\nSection 6 -- Term and Termination.\n\n  a. This Public License applies for the term of the Copyright and\n     Similar Rights licensed here. However, if You fail to comply with\n     this Public License, then Your rights under this Public License\n     terminate automatically.\n\n  b. Where Your right to use the Licensed Material has terminated under\n     Section 6(a), it reinstates:\n\n       1. automatically as of the date the violation is cured, provided\n          it is cured within 30 days of Your discovery of the\n          violation; or\n\n       2. upon express reinstatement by the Licensor.\n\n     For the avoidance of doubt, this Section 6(b) does not affect any\n     right the Licensor may have to seek remedies for Your violations\n     of this Public License.\n\n  c. For the avoidance of doubt, the Licensor may also offer the\n     Licensed Material under separate terms or conditions or stop\n     distributing the Licensed Material at any time; however, doing so\n     will not terminate this Public License.\n\n  d. Sections 1, 5, 6, 7, and 8 survive termination of this Public\n     License.\n\n\nSection 7 -- Other Terms and Conditions.\n\n  a. The Licensor shall not be bound by any additional or different\n     terms or conditions communicated by You unless expressly agreed.\n\n  b. Any arrangements, understandings, or agreements regarding the\n     Licensed Material not stated herein are separate from and\n     independent of the terms and conditions of this Public License.\n\n\nSection 8 -- Interpretation.\n\n  a. For the avoidance of doubt, this Public License does not, and\n     shall not be interpreted to, reduce, limit, restrict, or impose\n     conditions on any use of the Licensed Material that could lawfully\n     be made without permission under this Public License.\n\n  b. To the extent possible, if any provision of this Public License is\n     deemed unenforceable, it shall be automatically reformed to the\n     minimum extent necessary to make it enforceable. If the provision\n     cannot be reformed, it shall be severed from this Public License\n     without affecting the enforceability of the remaining terms and\n     conditions.\n\n  c. No term or condition of this Public License will be waived and no\n     failure to comply consented to unless expressly agreed to by the\n     Licensor.\n\n  d. Nothing in this Public License constitutes or may be interpreted\n     as a limitation upon, or waiver of, any privileges and immunities\n     that apply to the Licensor or You, including from the legal\n     processes of any jurisdiction or authority.\n\n\n=======================================================================\n\nCreative Commons is not a party to its public\nlicenses. Notwithstanding, Creative Commons may elect to apply one of\nits public licenses to material it publishes and in those instances\nwill be considered the “Licensor.” The text of the Creative Commons\npublic licenses is dedicated to the public domain under the CC0 Public\nDomain Dedication. Except for the limited purpose of indicating that\nmaterial is shared under a Creative Commons public license or as\notherwise permitted by the Creative Commons policies published at\ncreativecommons.org/policies, Creative Commons does not authorize the\nuse of the trademark \"Creative Commons\" or any other trademark or logo\nof Creative Commons without its prior written consent including,\nwithout limitation, in connection with any unauthorized modifications\nto any of its public licenses or any other arrangements,\nunderstandings, or agreements concerning use of licensed material. For\nthe avoidance of doubt, this paragraph does not form part of the\npublic licenses.\n\nCreative Commons may be contacted at creativecommons.org."
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"makeabledk/laravel-factory-enhanced\",\n    \"license\": \"CC-BY-SA-4.0\",\n    \"autoload\": {\n        \"psr-4\": {\n            \"Makeable\\\\LaravelFactory\\\\\": \"src/\"\n        },\n        \"files\": [\n            \"src/helpers.php\"\n        ]\n    },\n    \"require\": {\n        \"php\": \"^8.1\",\n        \"illuminate/database\": \"^10.0|^11.0|^12.0|^13.0\",\n        \"illuminate/support\": \"^10.0|^11.0|^12.0|^13.0\"\n    },\n    \"require-dev\": {\n        \"fakerphp/faker\": \"^1.21\",\n        \"laravel/laravel\": \"^10.0|^11.0|^12.0|^13.0\",\n        \"mockery/mockery\": \"^1.5\",\n        \"phpunit/phpunit\": \"^10.5.17|^11.0\"\n    },\n    \"autoload-dev\": {\n        \"psr-4\": {\n            \"Makeable\\\\LaravelFactory\\\\Tests\\\\\": \"tests/\",\n            \"Makeable\\\\LaravelFactory\\\\Tests\\\\Database\\\\Factories\\\\\": \"tests/database/factories\"\n        }\n    },\n    \"extra\": {\n        \"laravel\": {\n            \"providers\": [\n                \"Makeable\\\\LaravelFactory\\\\FactoryServiceProvider\"\n            ]\n        }\n    },\n    \"config\": {\n        \"sort-packages\": true\n    },\n    \"scripts\": {\n        \"test\": \"./vendor/bin/phpunit\"\n    },\n    \"minimum-stability\": \"dev\",\n    \"prefer-stable\": true\n}\n"
  },
  {
    "path": "phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" backupGlobals=\"false\" bootstrap=\"vendor/autoload.php\" colors=\"true\" processIsolation=\"false\" stopOnFailure=\"false\" xsi:noNamespaceSchemaLocation=\"https://schema.phpunit.de/10.5/phpunit.xsd\" cacheDirectory=\".phpunit.cache\" backupStaticProperties=\"false\">\n  <testsuites>\n    <testsuite name=\"Package Test Suite\">\n      <directory>./tests/</directory>\n    </testsuite>\n  </testsuites>\n  <php>\n    <ini name=\"display_errors\" value=\"1\"/>\n    <env name=\"APP_ENV\" value=\"testing\"/>\n    <server name=\"BCRYPT_ROUNDS\" value=\"4\"/>\n    <server name=\"CACHE_DRIVER\" value=\"array\"/>\n    <server name=\"MAIL_DRIVER\" value=\"array\"/>\n    <server name=\"QUEUE_CONNECTION\" value=\"sync\"/>\n    <server name=\"SESSION_DRIVER\" value=\"array\"/>\n  </php>\n  <source>\n    <include>\n      <directory suffix=\".php\">src/</directory>\n    </include>\n  </source>\n</phpunit>\n"
  },
  {
    "path": "readme.md",
    "content": "![Laravel Factory Enhanced - Supercharge your tests](https://raw.githubusercontent.com/makeabledk/laravel-factory-enhanced/master/banner-1.png)\n\n# Laravel Factory Enhanced 🔥\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/makeabledk/laravel-factory-enhanced.svg)](https://packagist.org/packages/makeabledk/laravel-factory-enhanced)\n[![Build Status](https://img.shields.io/github/workflow/status/makeabledk/laravel-factory-enhanced/Run%20tests?label=Tests)](https://github.com/makeabledk/laravel-factory-enhanced/actions)\n[![StyleCI](https://styleci.io/repos/117680722/shield?branch=master)](https://styleci.io/repos/117680722)\n\nBring the magic of eloquent relationships into the Laravel Factory. \n\nTraditionally if you wanted to factory a team with some users, you'd have to manually create the individual team and users and then tie them together afterwards. This can easily lead to very verbose tests.\n\n**Laravel 7.x and earlier**\n\n```php\n$team = factory(Team::class)->create();\n$users = factory(User::class)->times(2)->create();\nforeach ($users as $user) {\n    factory(TeamMember::class)->create([\n        'team_id' => $team,\n        'user_id' => $user,\n        'role' => 'admin'\n    ]);\n}\n```\n\n**Laravel 8.0 and later**\n\n```php\n$team = Team::factory()\n    ->hasAttached(\n        User::factory()->count(2),\n        ['role' => 'admin']\n    )\n    ->create();\n\n```\n\n**Laravel Factory Enhanced**\n\n```php\n$team = Team::factory()\n    ->with(2, 'users', ['pivot.role' => 'admin'])\n    ->create();\n```\n\n## Installation\n\nYou may install the package via composer\n\n```bash\ncomposer require makeabledk/laravel-factory-enhanced\n```\n\n\n### Versions\n\n**Laravel 8+ class based factories**\n\nVersion 4 and later of this package is compatible with the new class-based syntax introduced with Laravel 8.\n\n**Pre-Laravel 7 factories**\n\nVersion 3 and earlier of this package is compatible with the legacy `$factory->define()` syntax. Please find docs here [v3 documentation](https://github.com/makeabledk/laravel-factory-enhanced/tree/3.x):\n\n## Upgrade guide to v4\n\nThe majority of the refactoring needed to upgrade to v4 of this package, lies in rewriting factories to be compatible with Laravel class-based factories. \n\nIf you use [Laravel Shift](https://laravelshift.com) when upgrading to Laravel 8, a lot of this work will be automated, and you will be well on you way.\n\n### Rewriting to class based factories\n\nPlease use [Laravel Shift](https://laravelshift.com) for upgrading Laravel versions, or refer to the [official documentation](https://laravel.com/docs/8.x/database-testing) on how to write factories using the class-based approach.\n\n\n### Applying states\n\nReplace all occurrences of `->state('some-state')` with `->someState()` in your test suite.\n\n\n### Presets\n\nThe concept of presets which was introduced by this package may now simply be rewritten to states.\n\nAs such, replace all occurrences of `->preset('some-preset')` with `->somePreset()` in your test suite.\n\n\n### Times method\n\nReplace all occurrences of `->times(x)` with `->count(x)` in your test suite.\n\n\n### Factory helper syntax\n\nThis change is completely optional. If you wish, you may change all occurrence of `factory(SomeModel::class)` to `SomeModel::factory()` in your test suite. \n\n_If you choose to do so_, remember to add `use \\Makeable\\LaravelFactory\\Factory;` to all models.\n\n\n### Other breaking changes\n\nThe `odds()` method has been removed from the Factory instance.\n\n\n## Usage\n\nOnce the package is installed, your factories should extend `Makeable\\LaravelFactory\\Factory` rather than the native Laravel `Factory` class. \n\nAdditionally, please make sure to use the corresponding `Makeable\\LaravelFactory\\HasFactory` trait on your models.\n\nFor example:\n\n**app/Models/User.php**\n\n```php\n<?php\n\nnamespace App\\Models;\n\nuse Makeable\\LaravelFactory\\HasFactory;\n\nclass User \n{\n    use HasFactory;\n    \n    // ...\n}\n```\n\n**database/factories/UserFactory.php**\n\n```php\n<?php\n\nnamespace Database\\Factories;\n\nuse Makeable\\LaravelFactory\\Factory;\n\nclass UserFactory extends Factory\n{\n    public function definition()\n    {\n        return [\n            // ...\n        ];\n    }\n}\n```\n\nYou may now use all the native Laravel features you are used to, along with the additional functionality this package provides.\n\nIf you're not familiar with Laravel factories, please refer to the official documentation: https://laravel.com/docs/master/database-testing\n\n### Simple relationships\n\nYou may use the enhanced factory to create any additional relationships defined on the model.\n\nExample: A `Server` model with a `sites()` relationship (has-many)\n\n```php\nServer::factory()->with(3, 'sites')->create();\n```\n\nNote that you may still use any native functionality that you are used to, such as states and attributes:\n\n```php\nServer::factory()->online()->with(3, 'sites')->create([\n    'name' => 'production-1'\n]);\n```\n\n### Multiple relationships\n\nYou are free to specify multiple relationships on the same factory. \n\nGiven our previous `Server` model has another relationship called `team` (belongs-to), you may do:\n\n```php\nServer::factory()\n    ->with('team')\n    ->with(3, 'sites')\n    ->create();\n```\n\nNow you would have `1 team` that has `1 server` which has `3 sites`.\n\n\n### Nested relationships\n\nMoving on to the more advanced use-cases, you may also do nested relationships. \n\nFor instance we could rewrite our example from before using nesting:\n\n```php\nTeam::factory()\n    ->with(3, 'servers.sites')\n    ->create();\n```\nPlease note that the count '3' applies to *the final relationship*, in this case `sites`.\n\nIf you are wanting 2 servers each of which has 3 sites, you may write it as following:\n\n```php\nTeam::factory()    \n    ->with(2, 'servers')\n    ->with(3, 'servers.sites')\n    ->create();\n```\n\n### States in relationships\n\nJust as you may specify pre-defined states on the factoring model ([see official documentation](https://laravel.com/docs/master/database-testing#factory-states)), you may also apply the very same states on the relation.\n\n```php\nTeam::factory()    \n    ->with(2, 'online', 'servers')\n    ->create();\n```\n\nYou may finding yourself wanting a relationship in multiple states. In this case you may use the `andWith()` method.\n\n```php\nTeam::factory()    \n    ->with(2, 'online', 'servers')\n    ->andWith(1, 'offline', 'servers')\n    ->create();\n```\n\nBy using the `andWith` we will create a 'clean cut', so that no further calls to `with` can interfere with relations specified prior to the `andWith`. \n\nIn the above example any further nesting of relations will apply to the 'offline' server.\n\n```php\nTeam::factory()    \n    ->with(2, 'online', 'servers')\n    ->andWith(1, 'offline', 'servers')\n    ->with(3, 'servers.sites')\n    ->create();\n```\n\nThe above example will create 1x team that has\n\n- 2x online servers\n- 1x offline servers with 3 sites\n\n### Filling attributes in relationships\n\nYou may fill attributes on a relationship by passing them as an argument to the `with()` method.\n\n```php\nfactory(Team::class)    \n    ->with(2, 'servers', ['name' => 'laravel.com'])\n    ->create();\n```\n\nIf the relation is a belongs-to-many relationship, you may also fill attributes on the pivot model by prefixing the attribute name with `pivot.`.\n\n```php\nTeam::factory()    \n    ->with(2, 'users', ['pivot.role' => 'admin'])\n    ->create();\n```\n\n### Using apply()\n\nAll of the above examples of how you might configure a relationship using the `with()` method, can also be applied on the base model using the `apply()` method.\n\nFor example:\n\n```php\nServer::factory()\n    ->apply(2, 'online', ['name' => 'laravel.com'])\n    ->with(3, 'mysql', 'databases')\n    ->create();\n```\n\nThis would create 2 online servers each with 3 mysql databases.\n\nIn fact, by using the `HasFactory` trait from this package, you can even pass these arguments to the `::factory()` method itself:\n\n```php\nServer::factory(2, 'online', ['name' => 'laravel.com'])\n    ->with(3, 'mysql', 'databases')\n    ->create();\n```\n\n### Using closures for customization\n\nIn addition to passing *count* and *state* directly into the `with` function, you may also pass a closure that will receive the `FactoryBuilder` instance directly.\n\nIn the closure you can do everything you are used to on the `FactoryBuilder` - including nesting further relationships should you wish to.\n\n```php\nTeam::factory()    \n    ->with('servers', fn (ServerFactory $servers) => $servers\n        ->count(2)\n        ->active()\n        ->with(3, 'sites')\n    )\n    ->create();\n```\n\n\n### Factoring models with no defined factory\n\nTraditionally trying to use `Model::factory()` on a model with no defined factory would throw an exception. Not anymore!\n\nAfter installing this package, you are completely free to use the static `Model::factory()` method on any Eloquent model that uses the `Makeable\\LaravelFactory\\HasFactory` trait.\n\nFurthermore, this package brings back the good old `factory(Model::class)` helper function which you may use on any model, whether or not the model has a defined factory or uses the `HasFactory` trait.\n\n**Example**\n\n```php\nfactory(2, Server::class)->with(1, 'sites')->create();\n```\n\n## Available methods\n\nThese are the provided methods on the `Factory` instance in addition to the core methods.\n\n- apply\n- fill\n- fillPivot (only applicable on BelongsToMany\n- pipe\n- tap\n- with\n- andWith\n\n## Testing\n\nYou can run the tests with:\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nWe are happy to receive pull requests for additional functionality. Please see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Rasmus Christoffer Nielsen](https://github.com/rasmuscnielsen)\n- [All Contributors](../../contributors)\n\n## License\n\nAttribution-ShareAlike 4.0 International. Please see [License File](LICENSE.md) for more information.\n"
  },
  {
    "path": "src/ArgumentParser.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Support\\Arr;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Str;\n\nclass ArgumentParser\n{\n    public static function apply(Collection $arguments, Factory $factory): Factory\n    {\n        return $arguments->reduce(function (Factory $factory, $arg) {\n            if (is_null($arg)) {\n                return $factory;\n            }\n\n            if (is_numeric($arg)) {\n                return $factory->count($arg);\n            }\n\n            if (is_array($arg) && ! isset($arg[0])) {\n                return static::fill($factory, $arg);\n            }\n\n            if ($arg instanceof Model) {\n                return $factory->for($arg);\n            }\n\n            if (is_callable($arg) && ! is_string($arg)) {\n                return $factory->tap($arg);\n            }\n\n            if (is_string($arg) || (is_array($arg) && is_string($arg[0]))) {\n                return collect($arg)->reduce(fn ($factory, $method) => call_user_func([$factory, $method]), $factory);\n            }\n\n            throw new \\InvalidArgumentException('Unexpected argument: '.$arg);\n        }, $factory);\n    }\n\n    protected static function fill(Factory $factory, array $attributes): Factory\n    {\n        $pivotAttributes = [];\n\n        foreach ($attributes as $attribute => $value) {\n            if (Str::startsWith($attribute, 'pivot.')) {\n                $pivotAttributes[Str::after($attribute, 'pivot.')] = $value;\n\n                Arr::forget($attributes, $attribute);\n            }\n        }\n\n        return $factory\n            ->fill($attributes)\n            ->fillPivot($pivotAttributes);\n    }\n}\n"
  },
  {
    "path": "src/Concerns/EnhancedCount.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Concerns;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\ntrait EnhancedCount\n{\n    /**\n     * Overwrite core method to allow closures.\n     *\n     * @param  int|callable|null  $count\n     * @return $this\n     */\n    public function count($count): self\n    {\n        return $this->newInstance(['count' => $count]);\n    }\n\n    public function make($attributes = [], ?Model $parent = null)\n    {\n        return $this->withCalculatedCount(fn () => parent::make($attributes, $parent));\n    }\n\n    public function raw($attributes = [], ?Model $parent = null)\n    {\n        return $this->withCalculatedCount(fn () => parent::raw($attributes, $parent));\n    }\n\n    protected function withCalculatedCount(\\Closure $callback)\n    {\n        $backup = $this->count;\n\n        if (is_callable($this->count)) {\n            $this->count = call_user_func($this->count);\n        }\n\n        return tap($callback(), fn () => $this->count = $backup);\n    }\n}\n"
  },
  {
    "path": "src/Concerns/EnhancedRelationships.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Concerns;\n\nuse Closure;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\RelationRequest;\n\ntrait EnhancedRelationships\n{\n    protected int $currentBatch = 0;\n\n    protected array $relations = [];\n\n    protected array $pivot = [];\n\n    /**\n     * Build the model with specified relations.\n     *\n     * @param  mixed  ...$args\n     * @return static\n     */\n    public function with(...$args): self\n    {\n        return $this->loadRelation(\n            new RelationRequest($this->model, $this->currentBatch, $args)\n        );\n    }\n\n    /**\n     * Build relations in a new batch. Multiple batches can be\n     * created on the same relation, so that ie. multiple\n     * has-many relations can be configured differently.\n     *\n     * @param  mixed  ...$args\n     * @return static\n     */\n    public function andWith(...$args): self\n    {\n        return $this->newBatch()->with(...$args);\n    }\n\n    /**\n     * Load a RelationRequest onto current FactoryBuilder.\n     *\n     * @param  \\Makeable\\LaravelFactory\\RelationRequest  $request\n     * @return \\Makeable\\LaravelFactory\\Concerns\\EnhancedRelationships\n     */\n    public function loadRelation(RelationRequest $request): self\n    {\n        $related = $this->pushRelatedFactory($request);\n\n        // Recursively create factories until no further nesting.\n        if ($request->hasNesting()) {\n            $this->pushRelatedFactory($request, $related->loadRelation($request->createNestedRequest()));\n\n            return $this;\n        }\n\n        // Apply the request onto the final relationship factory.\n        $this->pushRelatedFactory($request, $related->apply(...$request->arguments));\n\n        return $this;\n    }\n\n    protected function pushRelatedFactory(RelationRequest $request, ?self $factory = null): Factory\n    {\n        $path = implode('.', [\n            $request->loadMethod(),\n            $request->getRelationName(),\n            $request->batch,\n        ]);\n\n        $factory = $factory\n            ?? data_get($this->relations, $path)\n            ?? static::factoryForModel($request->getRelatedClass());\n\n        return tap($factory, fn () => data_set($this->relations, $path, $factory));\n    }\n\n    protected function withRelationsApplied(Closure $callback)\n    {\n        $self = $this;\n\n        foreach ($this->relations as $method => $relations) {\n            foreach ($relations as $relationship => $factories) {\n                foreach ($factories as $batch => $factory) {\n                    if ($factory->count === 0) {\n                        continue;\n                    }\n\n                    if ($method === 'for') {\n                        $factory = $factory->count(null);\n                    }\n\n                    if ($this->connection) {\n                        $factory = $factory->connection($this->connection);\n                    }\n\n                    $args = $method === RelationRequest::BelongsToMany\n                        ? [$factory, $factory->mergedPivotAttributes(), $relationship]\n                        : [$factory, $relationship];\n\n                    $self = $self->$method(...$args);\n                }\n            }\n        }\n\n        return call_user_func($callback->bindTo($self));\n    }\n\n    protected function mergedPivotAttributes(): Closure\n    {\n        return function (Model $model) {\n            return collect($this->pivot)->reduce(function ($merged, $pivot) use ($model) {\n                return array_merge($merged, is_callable($pivot) ? call_user_func($pivot, $model) : $pivot);\n            }, []);\n        };\n    }\n\n    protected function newBatch(): self\n    {\n        $this->currentBatch++;\n\n        return $this;\n    }\n\n    // Core method overwrites\n\n    protected function createChildren(Model $model)\n    {\n        $this->withRelationsApplied(fn () => parent::createChildren($model));\n    }\n\n    protected function getRawAttributes(?Model $parent)\n    {\n        return $this->withRelationsApplied(fn () => parent::getRawAttributes($parent));\n    }\n}\n"
  },
  {
    "path": "src/Concerns/EnhancedSequence.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Concerns;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\Sequence;\n\ntrait EnhancedSequence\n{\n    /**\n     * Support a \"method name\" string given as sequence value.\n     * It will invoke the method on the Factory and grab\n     * any attributes the method has applied.\n     */\n    public function sequence(...$values): self\n    {\n        $values = array_map(function ($value) {\n            if (is_string($value) && method_exists($this, $value)) {\n                return function () use ($value) {\n                    return (new static)->$value()->count(null)->raw();\n                };\n            }\n\n            return $value;\n        }, $values);\n\n        $sequence = new Sequence(...$values);\n\n        return $this->state(function () use ($sequence) {\n            return ($attributes = $sequence()) instanceof \\Closure\n                ? $attributes()\n                : $attributes;\n        });\n    }\n}\n"
  },
  {
    "path": "src/Factory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory;\n\nuse Makeable\\LaravelFactory\\Concerns\\EnhancedCount;\nuse Makeable\\LaravelFactory\\Concerns\\EnhancedRelationships;\nuse Makeable\\LaravelFactory\\Concerns\\EnhancedSequence;\n\nclass Factory extends \\Illuminate\\Database\\Eloquent\\Factories\\Factory\n{\n    use EnhancedCount,\n        EnhancedRelationships,\n        EnhancedSequence;\n\n    protected bool $mutating = false;\n\n    public static function factoryForModel($modelName): self\n    {\n        if (method_exists($modelName, 'newFactory') && ($factory = $modelName::newFactory())) {\n            return $factory;\n        }\n\n        $factory = static::resolveFactoryName($modelName);\n\n        if (is_string($factory) && class_exists($factory)) {\n            return $factory::new();\n        }\n\n        return Factory::new()->tap(fn ($factory) => $factory->model = $modelName);\n    }\n\n    public function apply(...$args): self\n    {\n        return ArgumentParser::apply(collect($args), $this);\n    }\n\n    public function definition()\n    {\n        return [];\n    }\n\n    public function fill($attributes): self\n    {\n        return $this->state($attributes);\n    }\n\n    public function fillPivot($attributes): self\n    {\n        return $this->newInstance()->tap(fn (self $factory) => array_push($factory->pivot, $attributes));\n    }\n\n    public function pipe(callable $callback): self\n    {\n        return call_user_func($callback, $this);\n    }\n\n    public function tap($callback = null): self\n    {\n        $this->mutating = true;\n\n        call_user_func($callback, $this);\n\n        $this->mutating = false;\n\n        return $this;\n    }\n\n    protected function newInstance(array $arguments = [])\n    {\n        if ($this->mutating) {\n            foreach ($arguments as $argument => $value) {\n                $this->$argument = $value;\n            }\n\n            return $this;\n        }\n\n        return parent::newInstance($arguments)->tap(function (self $factory) {\n            $factory->relations = $this->relations;\n            $factory->pivot = $this->pivot;\n            $factory->model = $this->model;\n        });\n    }\n}\n"
  },
  {
    "path": "src/FactoryServiceProvider.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass FactoryServiceProvider extends ServiceProvider\n{\n    //\n}\n"
  },
  {
    "path": "src/HasFactory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory;\n\ntrait HasFactory\n{\n    /**\n     * Get a new factory instance for the model.\n     *\n     * @param  mixed  $parameters\n     * @return \\Makeable\\LaravelFactory\\Factory\n     */\n    public static function factory(...$parameters)\n    {\n        return Factory::factoryForModel(static::class)->apply(...$parameters);\n    }\n}\n"
  },
  {
    "path": "src/RelationRequest.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory;\n\nuse BadMethodCallException;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsTo;\nuse Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany;\nuse Illuminate\\Database\\Eloquent\\Relations\\HasOneOrMany;\nuse Illuminate\\Database\\Eloquent\\Relations\\Relation;\nuse Illuminate\\Support\\Collection;\n\nclass RelationRequest\n{\n    public const HasMany = 'has';\n    public const BelongsToMany = 'hasAttached';\n    public const BelongsTo = 'for';\n\n    /**\n     * The parent model requesting relations.\n     */\n    protected string $model;\n\n    public int $batch;\n\n    public Collection $arguments;\n\n    protected ?Relation $cachedRelation;\n\n    /**\n     * The (possibly nested) relations path.\n     *\n     * @var string\n     */\n    public $path;\n\n    /**\n     * Create a new relationship request.\n     *\n     * @param  $model\n     * @param  $batch\n     * @param  mixed  $arguments\n     */\n    public function __construct($model, $batch, $arguments)\n    {\n        [$this->model, $this->batch, $this->arguments] = [$model, $batch, collect($arguments)];\n\n        $this->extractRelationFromArguments();\n        $this->failOnMissingRelation();\n    }\n\n    /**\n     * Create a new relationship request for nested relations.\n     *\n     * @return RelationRequest\n     */\n    public function createNestedRequest()\n    {\n        return new static(\n            $this->getRelatedClass(),\n            $this->batch,\n            $this->arguments->values()->push($this->getNestedPath())\n        );\n    }\n\n    /**\n     * Get the nested path beyond immediate relation.\n     *\n     * @param  string|null  $path\n     * @return string\n     */\n    public function getNestedPath($path = null)\n    {\n        $nested = explode('.', $path ?: $this->path);\n\n        array_shift($nested);\n\n        return implode('.', $nested);\n    }\n\n    /**\n     * Get the class name of the related eloquent model.\n     *\n     * @return string\n     */\n    public function getRelatedClass()\n    {\n        return get_class($this->getRelation()->getRelated());\n    }\n\n    protected function getRelation()\n    {\n        $relation = $this->getRelationName();\n\n        return $this->cachedRelation ??= $this->newModel()->$relation();\n    }\n\n    /**\n     * Get the name of the immediate relation.\n     *\n     * @param  string|null  $path\n     * @return mixed\n     */\n    public function getRelationName($path = null)\n    {\n        $nested = explode('.', $path ?: $this->path);\n\n        return array_shift($nested);\n    }\n\n    public function loadMethod()\n    {\n        if ($this->getRelation() instanceof BelongsToMany) {\n            return static::BelongsToMany;\n        }\n\n        if ($this->getRelation() instanceof BelongsTo) {\n            return static::BelongsTo;\n        }\n\n        if ($this->getRelation() instanceof HasOneOrMany) {\n            return static::HasMany;\n        }\n\n        throw new BadMethodCallException('Unsupported relation type '.get_class($this->getRelation()));\n    }\n\n    /**\n     * Check if has nesting.\n     *\n     * @return bool\n     */\n    public function hasNesting()\n    {\n        return strpos($this->path, '.') !== false;\n    }\n\n    /**\n     * Loop through arguments to detect a relation name.\n     */\n    protected function extractRelationFromArguments()\n    {\n        $this->arguments = $this->arguments->reject(function ($arg) {\n            if ($match = (is_string($arg) && $this->isValidRelation($arg))) {\n                $this->path = $arg;\n            }\n\n            return $match;\n        });\n    }\n\n    /**\n     * Check if a string represents a valid relation path.\n     *\n     * @param  $path\n     * @return bool\n     */\n    protected function isValidRelation($path)\n    {\n        $model = $this->newModel();\n        $relation = $this->getRelationName($path);\n\n        return method_exists($model, $relation) && $model->$relation() instanceof Relation;\n    }\n\n    /**\n     * @return Model\n     */\n    protected function newModel()\n    {\n        return new $this->model;\n    }\n\n    /**\n     * Fail build with a readable exception message.\n     */\n    protected function failOnMissingRelation()\n    {\n        if (! $this->path) {\n            throw new BadMethodCallException(\n                'No matching relations could be found on model ['.$this->model.']. '.\n                'Following possible relation names was checked: '.\n                (\n                    ($testedRelations = $this->getPossiblyIntendedRelationships())->isEmpty()\n                        ? '[NO POSSIBLE RELATION NAMES FOUND]'\n                        : '['.$testedRelations->implode(', ').']'\n                )\n            );\n        }\n    }\n\n    /**\n     * Give the developer a readable list of possibly arguments\n     * that they might have intended could be a relation,\n     * but was invalid. Helpful for debugging purposes.\n     *\n     * @return Collection\n     */\n    protected function getPossiblyIntendedRelationships()\n    {\n        return $this->arguments\n            ->filter(function ($arg) {\n                return is_string($arg) || is_null($arg);\n            })\n            ->map(function ($arg) {\n                return is_null($arg) ? 'NULL' : \"'\".$arg.\"'\";\n            });\n    }\n}\n"
  },
  {
    "path": "src/helpers.php",
    "content": "<?php\n\nnamespace {\n    if (! function_exists('factory')) {\n        function factory($model, ...$arguments)\n        {\n            return \\Makeable\\LaravelFactory\\Factory::factoryForModel($model)->apply(...$arguments);\n        }\n    }\n}\n\nnamespace Makeable\\LaravelFactory {\n    use Illuminate\\Database\\Eloquent\\Model;\n\n    function count($count)\n    {\n        return fn (Factory $factory) => $factory->count($count);\n    }\n\n    function fill($attributes)\n    {\n        return fn (Factory $factory) => $factory->fill($attributes);\n    }\n\n    function inherit(...$attributes)\n    {\n        return fn (Factory $factory) => $factory->fill(function ($attrs, Model $parent) use ($attributes) {\n            return $parent->only($attributes);\n        });\n    }\n\n    function sequence(...$sequence)\n    {\n        return fn (Factory $factory) => $factory->sequence(...$sequence);\n    }\n}\n"
  },
  {
    "path": "tests/Feature/FactoryTest.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Feature;\n\nuse Illuminate\\Database\\Eloquent\\Collection;\nuse Illuminate\\Database\\Eloquent\\Factories\\Sequence;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Company;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Customer;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Department;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Image;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\User;\nuse Makeable\\LaravelFactory\\Tests\\TestCase;\n\nclass FactoryTest extends TestCase\n{\n    use RefreshDatabase;\n\n    /** @test **/\n    public function it_creates_models_with_no_relations()\n    {\n        $this->assertInstanceOf(User::class, User::factory()->create());\n    }\n\n    /** @test **/\n    public function it_creates_models_without_prior_definitions()\n    {\n        $this->assertInstanceOf(Customer::class, Customer::factory()->create());\n    }\n\n    /** @test **/\n    public function it_creates_models_even_when_no_factory_exists()\n    {\n        $this->assertInstanceOf(Image::class, Image::factory()->create([\n            'imageable_type' => 'Foo',\n            'imageable_id' => 1,\n        ]));\n    }\n\n    /** @test **/\n    public function it_creates_models_on_a_custom_connection()\n    {\n        $company = Company::factory()\n            ->connection('secondary')\n            ->create(['name' => 'Evil corp']);\n\n        $this->assertNull(Company::query()->where('name', 'Evil corp')->first());\n        $this->assertEquals($company->id, Company::on('secondary')->where('name', 'Evil corp')->first()->id);\n    }\n\n    /** @test **/\n    public function it_makes_models_on_a_custom_connection()\n    {\n        $company = Company::factory()\n            ->connection('secondary')\n            ->make(['name' => 'Evil corp']);\n\n        $this->assertEquals('secondary', $company->getConnectionName());\n    }\n\n    /** @test **/\n    public function it_supports_giving_a_closure_as_count()\n    {\n        $companies = Company::factory()->count(new Sequence(1, 2));\n\n        $this->assertEquals(1, $companies->make()->count());\n        $this->assertEquals(2, $companies->make()->count());\n    }\n\n//    /** @test **/\n//    public function it_applies_closures_when_a_condition_is_met()\n//    {\n//        $createTwice = function ($builder) {\n//            $builder->times(2);\n//        };\n//\n//        $this->assertInstanceOf(User::class, User::factory()->when(false, $createTwice)->create());\n//        $this->assertInstanceOf(Collection::class, User::factory()->when(true, $createTwice)->create());\n//    }\n//\n//    /** @test **/\n//    public function it_applies_closures_given_certain_odds()\n//    {\n//        $createTwice = function ($builder) {\n//            $builder->times(2);\n//        };\n//\n//        // With decimal\n//        $this->assertInstanceOf(User::class, User::factory()->odds(0 / 1, $createTwice)->create());\n//        $this->assertInstanceOf(Collection::class, User::factory()->odds(1 / 1, $createTwice)->create());\n//\n//        // With 0-100\n//        $this->assertInstanceOf(User::class, User::factory()->odds(0, $createTwice)->create());\n//        $this->assertInstanceOf(Collection::class, User::factory()->odds(100, $createTwice)->create());\n//\n//        // With string percentage\n//        $this->assertInstanceOf(User::class, User::factory()->odds('0%', $createTwice)->create());\n//        $this->assertInstanceOf(Collection::class, User::factory()->odds('100%', $createTwice)->create());\n//    }\n\n    /** @test **/\n    public function a_builder_can_be_tapped()\n    {\n        $createTwice = function ($builder) {\n            $builder->count(2);\n        };\n\n        $this->assertInstanceOf(Collection::class, User::factory()->tap($createTwice)->create());\n    }\n\n    /** @test **/\n    public function it_executes_defined_after_callbacks()\n    {\n        $factory = Department::factory()\n            ->afterMaking(function ($department) {\n                $department->forceFill(['active' => 1]);\n            })\n            ->afterCreating(function ($department) {\n                $department->forceFill(['flagship' => 1]);\n            });\n\n        $this->assertEquals(1, ($made = $factory->make())->active);\n        $this->assertEquals(0, $made->flagship);\n\n        $this->assertEquals(1, ($created = $factory->create())->active);\n        $this->assertEquals(1, $created->flagship);\n    }\n\n//    /** @test **/\n//    public function regression_it_doesnt_throw_missing_state_exception_when_has_after_callback()\n//    {\n//        )->factory((Department::class, 'undefined-state', function ($department) {\n//            $department->forceFill(['name' => 'HQ']);\n//        });\n//\n//        $this->assertEquals('HQ', Department::factory())->state('undefined-state')->make()->name);\n//\n//        unset(app(StateManager::class)->afterMaking[Company::class]);\n//    }\n\n//    /** @test **/\n//    public function regression_it_passes_inline_attributes_to_definitions()\n//    {\n//        $factory = $this->factory();\n//        $factory->defineAs(Customer::class, 'special', function (Generator $faker, array $attributes) {\n//            $this->assertEquals('bar', $attributes['foo']);\n//\n//            return [];\n//        });\n//\n//        $customer = $factory->of(Customer::class, 'special')->make(['foo' => 'bar']);\n//\n//        $this->assertEquals('bar', $customer->foo);\n//\n//        unset($factory[Customer::class]['special']);\n//    }\n\n    /** @test **/\n    public function regression_it_ignores_callables_when_expanding_attributes()\n    {\n        $company = Company::factory()->create([\n            'tags' => ['Storage', 'Data'],\n        ]);\n\n        $this->assertEquals(['Storage', 'Data'], $company->tags);\n    }\n\n    /** @test **/\n    public function regression_it_expands_closures_in_definition_attributes()\n    {\n        $company = Company::factory()->withOwner()->create();\n\n        $this->assertInstanceOf(User::class, $company->owner);\n    }\n}\n"
  },
  {
    "path": "tests/Feature/RelationsTest.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Feature;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\Sequence;\nuse Illuminate\\Database\\Events\\QueryExecuted;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Illuminate\\Support\\Facades\\DB;\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Company;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Department;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Image;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\User;\nuse Makeable\\LaravelFactory\\Tests\\TestCase;\n\nuse function Makeable\\LaravelFactory\\count;\nuse function Makeable\\LaravelFactory\\fill;\nuse function Makeable\\LaravelFactory\\inherit;\nuse function Makeable\\LaravelFactory\\sequence;\n\nclass RelationsTest extends TestCase\n{\n    use RefreshDatabase;\n\n    // DIFFERENT RELATIONSHIP TYPES\n\n    /** @test **/\n    public function it_creates_models_with_belongs_to_relations()\n    {\n        $company = Company::factory()\n            ->with('owner')\n            ->create();\n\n        $this->assertInstanceOf(Company::class, $company);\n        $this->assertEquals(1, $company->owner->id);\n    }\n\n    /** @test **/\n    public function it_creates_models_with_has_many_relations()\n    {\n        $company = Company::factory()\n            ->with(2, 'departments')\n            ->create();\n\n        $this->assertInstanceOf(Company::class, $company);\n        $this->assertInstanceOf(Department::class, $company->departments->first());\n        $this->assertEquals(2, $company->departments->count());\n    }\n\n    /** @test **/\n    public function it_creates_models_with_morph_many_relations()\n    {\n        $company = Company::factory()\n            ->with('logo')\n            ->create();\n\n        $this->assertInstanceOf(Company::class, $company);\n        $this->assertInstanceOf(Image::class, $company->logo);\n    }\n\n    /** @test **/\n    public function it_creates_models_with_belongs_to_many_relations()\n    {\n        $department = Department::factory()\n            ->with(2, 'employees')\n            ->create();\n\n        $this->assertInstanceOf(User::class, $department->employees->first());\n        $this->assertEquals(2, $department->employees->count());\n    }\n\n    /** @test **/\n    public function it_creates_models_with_multiple_relations()\n    {\n        $company = Company::factory()\n            ->with('owner')\n            ->with(2, 'departments')\n            ->create();\n\n        $this->assertInstanceOf(User::class, $company->owner);\n        $this->assertInstanceOf(Department::class, $company->departments->first());\n    }\n\n    // FUNCTIONALITY AND BEHAVIOR\n\n    /** @test **/\n    public function it_creates_related_models_on_the_same_connection()\n    {\n        $queries = [];\n\n        DB::listen(function (QueryExecuted $e) use (&$queries) {\n            $queries[$e->connectionName][] = $e->sql;\n        });\n\n        Company::factory()\n            ->connection('secondary')\n            ->for(User::factory(), 'owner')\n            ->with('owner') // belongs-to\n            ->with(1, 'departments') // has-many\n            ->with(1, 'departments.employees') // belongs-to-many\n            ->create();\n\n        $this->assertNull(data_get($queries, 'primary'));\n        $this->assertCount(5, data_get($queries, 'secondary'));\n\n        $company = Company::on('secondary')->with('owner', 'departments.employees')->latest()->first();\n\n        $this->assertInstanceOf(User::class, $company->owner);\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertEquals(1, $company->departments->first()->employees->count());\n    }\n\n    /** @test **/\n    public function the_same_relation_can_be_created_multiple_times_using_andWith()\n    {\n        $company = Company::factory()\n            ->with('owner')\n            ->with(1, 'departments')\n            ->andWith(1, 'departments.manager')\n            ->create();\n\n        $this->assertEquals(2, $company->departments->count());\n        $this->assertNull($company->departments->first()->manager);\n        $this->assertInstanceOf(User::class, $company->departments->last()->manager);\n    }\n\n    /** @test **/\n    public function additional_attributes_can_be_passed_inline_for_relations()\n    {\n        $company = Company::factory()\n            ->with(1, 'departments', ['active' => 1])\n            ->with('departments.manager', ['password' => 'foobar'])\n            ->create();\n\n        $this->assertEquals(1, $company->departments->first()->active);\n        $this->assertEquals('foobar', $company->departments->first()->manager->password);\n    }\n\n    /** @test **/\n    public function it_throws_a_bad_method_call_on_missing_relations()\n    {\n        $this->expectException(\\BadMethodCallException::class);\n        $this->expectExceptionMessageMatches('/invalidRelation/');\n        Company::factory()->with(1, 'invalidRelation')->create();\n    }\n\n    /** @test **/\n    public function it_accepts_pivot_attributes_on_belongs_to_many_relations()\n    {\n        $department = Department::factory()->with(1, 'employees', function ($employee) {\n            return $employee->fillPivot(['started_at' => '2019-01-01 00:00:00']);\n        })->create();\n\n        $employees = $department->employees()->withPivot('started_at')->get();\n\n        $this->assertEquals('2019-01-01 00:00:00', $employees->first()->pivot->started_at);\n        $this->assertEquals(1, $employees->count());\n    }\n\n    /** @test **/\n    public function it_accepts_closures_as_pivot_attributes_and_they_will_evaluate_on_each_model()\n    {\n        [$i, $dates] = [0, [now()->subMonth(), now()->subDay()]];\n\n        $department = Department::factory()\n            ->with(2, 'employees', function ($employee) use ($dates, &$i) {\n                return $employee->fillPivot(function (Department $department) use ($dates, &$i) {\n                    return ['started_at' => $dates[$i++]];\n                });\n            })->create();\n\n        $employees = $department->employees()->withPivot('started_at')->get();\n\n        $this->assertEquals(2, $employees->count());\n        $this->assertEquals($dates[0]->toDateTimeString(), $employees->get(0)->pivot->started_at);\n        $this->assertEquals($dates[1]->toDateTimeString(), $employees->get(1)->pivot->started_at);\n    }\n\n    /** @test **/\n    public function regression_null_arguments_will_parse_as_state_and_then_ignored()\n    {\n        $company = Company::factory()\n            ->with(1, 'departments', null)\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n    }\n\n    /** @test **/\n    public function regression_parent_model_is_available_as_second_argument()\n    {\n        // Laravel syntax\n        $company = Company::factory()\n            ->has(\n                Department::factory()\n                    ->count(2)\n                    ->state(function (array $attributes, Company $company) {\n                        return ['name' => $company->name.': Department'];\n                    })\n            )\n            ->create();\n\n        $this->assertStringContainsString($company->name, $company->departments->first()->name);\n\n        // Enhanced syntax\n        $company = Company::factory()\n            ->with(2, 'departments', function ($builder) {\n                $builder->fill(fn ($department, $company) => ['name' => $company->name.': Department']);\n            })\n            ->create();\n\n        $this->assertStringContainsString($company->name, $company->departments->first()->name);\n    }\n\n    // NESTED RELATIONS\n\n    /** @test **/\n    public function it_creates_models_with_nested_relations()\n    {\n        $company = Company::factory()\n            ->with('owner')\n            ->with('departments.manager')\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertInstanceOf(User::class, $company->departments->first()->manager);\n    }\n\n    /** @test **/\n    public function nested_relations_can_be_built_by_closures()\n    {\n        $company = Company::factory()\n            ->with('departments', function (Factory $departments) {\n                return $departments\n                    ->fill(['name' => 'foo'])\n                    ->count(2)\n                    ->with('manager');\n            })\n            ->create();\n\n        $this->assertEquals(2, $company->departments->count());\n        $this->assertEquals('foo', $company->departments->first()->name);\n        $this->assertInstanceOf(User::class, $company->departments->first()->manager);\n        $this->assertNotEquals(\n            $company->departments->get(0)->manager->id,\n            $company->departments->get(1)->manager->id\n        );\n    }\n\n    /** @test **/\n    public function nested_relations_can_be_specified_separate_function_calls()\n    {\n        $company = Company::factory()\n            ->with('owner')\n            ->with(1, 'departments')\n            ->with(1, 'departments.manager')\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertInstanceOf(User::class, $company->departments->first()->manager);\n    }\n\n    /** @test **/\n    public function it_accepts_model_instances_as_for_belongs_to()\n    {\n        // Using apply\n        $company = Company::factory()->create();\n        $department = Department::factory()->apply($company)->create();\n        $this->assertEquals($company->id, $department->company_id);\n\n        // Using with\n        $company = Company::factory()->create();\n        $manager = User::factory()\n            ->with(1, 'departments', $company)\n            ->create();\n        $this->assertEquals($company->id, $manager->departments->first()->company_id);\n    }\n\n    // HELPER FUNCTIONS\n\n    /** @test **/\n    public function count_helper_may_be_used_for_dynamic_expressions()\n    {\n        $companies = Company::factory()\n            ->count(2)\n            ->with(count(new Sequence(1, 2)), 'departments')\n            ->create();\n\n        $this->assertEquals(1, $companies->first()->departments->count());\n        $this->assertEquals(2, $companies->last()->departments->count());\n    }\n\n    /** @test **/\n    public function fill_helper_may_be_used_to_access_parent()\n    {\n        $company = Company::factory()\n            ->with(1, 'departments', fill(fn ($attributes, Company $parent) => ['name' => $parent->name]))\n            ->create();\n\n        $this->assertEquals($company->name, $company->departments->first()->name);\n    }\n\n    /** @test **/\n    public function inherit_helper_may_be_used_to_fill_attributes_from_parent()\n    {\n        $company = Company::factory()\n            ->with(1, 'departments', inherit('name'))\n            ->create();\n\n        $this->assertEquals($company->name, $company->departments->first()->name);\n    }\n\n    /** @test **/\n    public function sequence_helper_may_be_used_to_apply_different_states()\n    {\n        $company = Company::factory()\n            ->with(2, 'customers', sequence('happy', 'unhappy'))\n            ->create();\n\n        $this->assertEquals(5, $company->customers->first()->satisfaction);\n        $this->assertEquals(1, $company->customers->last()->satisfaction);\n    }\n\n    /** @test **/\n    public function regression_it_doesnt_create_belongs_to_relations_when_given_a_count_of_zero()\n    {\n        $company = Company::factory()\n            ->with(0, 'owner')\n            ->create();\n\n        $this->assertInstanceOf(Company::class, $company);\n        $this->assertNull($company->owner);\n    }\n}\n"
  },
  {
    "path": "tests/Feature/StateTest.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Feature;\n\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Company;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Customer;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\User;\nuse Makeable\\LaravelFactory\\Tests\\TestCase;\n\nclass StateTest extends TestCase\n{\n    use RefreshDatabase;\n\n    /** @test **/\n    public function it_can_apply_a_state()\n    {\n        $customer = Customer::factory()->happy()->create();\n\n        $this->assertEquals(5, $customer->satisfaction);\n    }\n\n    /** @test **/\n    public function it_filters_null_args()\n    {\n        $customer = Customer::factory()->apply(null)->create();\n\n        $this->assertInstanceOf(Customer::class, $customer);\n    }\n\n    /** @test **/\n    public function it_throws_exception_when_missing_state()\n    {\n        $this->expectException(\\BadMethodCallException::class);\n\n        Customer::factory()->foobar()->create();\n    }\n\n    /** @test **/\n    public function multiple_states_can_be_passed_for_relations_inline_individually()\n    {\n        $company = Company::factory()\n            ->with(1, 'active', 'flagship', 'departments')\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertEquals(1, $company->departments->first()->active);\n        $this->assertEquals(1, $company->departments->first()->flagship);\n    }\n\n    /** @test **/\n    public function multiple_states_can_be_passed_for_relations_inline_as_array()\n    {\n        $company = Company::factory()\n            ->with(1, ['active', 'flagship'], 'departments')\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertEquals(1, $company->departments->first()->active);\n        $this->assertEquals(1, $company->departments->first()->flagship);\n    }\n\n    /** @test **/\n    public function it_can_apply_what_was_formerly_know_as_a_preset()\n    {\n        $company = Company::factory()->startup()->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertEquals(1, $company->departments->first()->employees->count());\n    }\n\n    /** @test **/\n    public function presets_can_be_passed_for_relations_inline()\n    {\n        $company = Company::factory()\n            ->with(1, 'mediumSized', 'departments')\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertEquals(4, $company->departments->first()->employees->count());\n        $this->assertInstanceOf(User::class, $company->departments->first()->manager);\n    }\n\n    /** @test **/\n    public function regression_states_works_with_nested_relations()\n    {\n        $company = Company::factory()\n            ->with(1, 'active', 'departments')\n            ->with(2, 'departments.employees')\n            ->create();\n\n        $this->assertEquals(1, $company->departments->count());\n        $this->assertEquals(2, $company->departments->first()->employees->count());\n        $this->assertEquals(1, $company->departments->first()->active);\n    }\n\n    /** @test **/\n    public function sequence_accepts_state_names()\n    {\n        $customer = Customer::factory()->sequence('happy', 'unhappy', ['satisfaction' => 3]);\n\n        $this->assertEquals(5, $customer->make()->satisfaction);\n        $this->assertEquals(1, $customer->make()->satisfaction);\n        $this->assertEquals(3, $customer->make()->satisfaction);\n    }\n}\n"
  },
  {
    "path": "tests/Stubs/Company.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Stubs;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Company extends Model\n{\n    use HasFactory;\n\n    protected $casts = [\n        'tags' => 'array',\n    ];\n\n    public function customers()\n    {\n        return $this->hasMany(Customer::class);\n    }\n\n    public function departments()\n    {\n        return $this->hasMany(Department::class);\n    }\n\n    public function logo()\n    {\n        return $this->morphOne(Image::class, 'imageable');\n    }\n\n    public function owner()\n    {\n        return $this->belongsTo(User::class, 'owner_id');\n    }\n}\n"
  },
  {
    "path": "tests/Stubs/Customer.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Stubs;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Customer extends Model\n{\n    use HasFactory;\n}\n"
  },
  {
    "path": "tests/Stubs/Department.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Stubs;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Department extends Model\n{\n    use HasFactory;\n\n    public function company()\n    {\n        return $this->belongsTo(Company::class);\n    }\n\n    public function employees()\n    {\n        return $this->belongsToMany(User::class, 'employees');\n    }\n\n    public function manager()\n    {\n        return $this->belongsTo(User::class, 'manager_id');\n    }\n}\n"
  },
  {
    "path": "tests/Stubs/HasFactory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Stubs;\n\ntrait HasFactory\n{\n    use \\Makeable\\LaravelFactory\\HasFactory;\n\n    /**\n     * Create a new factory instance for the model.\n     *\n     * @return \\Illuminate\\Database\\Eloquent\\Factories\\Factory\n     */\n    protected static function newFactory()\n    {\n        $name = '\\\\Makeable\\\\LaravelFactory\\\\Tests\\\\Database\\\\Factories\\\\'.class_basename(static::class).'Factory';\n\n        if (class_exists($name)) {\n            return new $name;\n        }\n    }\n}\n"
  },
  {
    "path": "tests/Stubs/Image.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Stubs;\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Image extends Model\n{\n    use HasFactory;\n\n    public function imageable()\n    {\n        return $this->morphTo();\n    }\n}\n"
  },
  {
    "path": "tests/Stubs/User.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Stubs;\n\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable\n{\n    use HasFactory;\n\n    protected $fillable = [\n        'name', 'email', 'password',\n    ];\n\n    protected $hidden = [\n        'password', 'remember_token',\n    ];\n\n    protected $casts = [\n        'email_verified_at' => 'datetime',\n    ];\n\n    public function departments()\n    {\n        return $this->hasMany(Department::class, 'manager_id');\n    }\n}\n"
  },
  {
    "path": "tests/TestCase.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests;\n\nuse Illuminate\\Foundation\\Testing\\TestCase as BaseTestCase;\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\FactoryServiceProvider;\n\nclass TestCase extends BaseTestCase\n{\n    protected $connectionsToTransact = [\n        'primary',\n        'secondary',\n    ];\n\n    /**\n     * Creates the application.\n     *\n     * @return \\Illuminate\\Foundation\\Application\n     */\n    public function createApplication()\n    {\n        /** @var \\Illuminate\\Foundation\\Application $app */\n        $app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';\n        $app->make(\\Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap();\n        $app->register(FactoryServiceProvider::class);\n        $app->useDatabasePath(__DIR__.'/database');\n\n        $app['config']->set('database.default', 'primary');\n        $app['config']->set('database.connections.primary', [\n            'driver' => 'sqlite',\n            'database' => ':memory:',\n            'prefix' => '',\n        ]);\n        $app['config']->set('database.connections.secondary', [\n            'driver' => 'sqlite',\n            'database' => ':memory:',\n            'prefix' => '',\n        ]);\n\n        return $app;\n    }\n\n    /**\n     * @param  null  $class\n     * @return Factory\n     */\n    protected function factory($class = null)\n    {\n        return Factory::factoryForModel($class);\n    }\n}\n"
  },
  {
    "path": "tests/database/factories/CompanyFactory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Database\\Factories;\n\nuse App\\Models\\User;\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Company;\n\nclass CompanyFactory extends Factory\n{\n    protected $model = Company::class;\n\n    public function definition()\n    {\n        return [\n            'name' => $this->faker->company,\n        ];\n    }\n\n    public function startup()\n    {\n        return $this\n            ->with(1, 'departments')\n            ->with(1, 'departments.employees');\n    }\n\n    public function withOwner()\n    {\n        return $this->state([\n            'owner_id' => function () {\n                return User::factory()->create()->id;\n            },\n        ]);\n    }\n}\n"
  },
  {
    "path": "tests/database/factories/CustomerFactory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Database\\Factories;\n\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Customer;\n\nclass CustomerFactory extends Factory\n{\n    protected $model = Customer::class;\n\n    public function happy()\n    {\n        return $this->state([\n            'satisfaction' => 5,\n        ]);\n    }\n\n    public function unhappy()\n    {\n        return $this->state([\n            'satisfaction' => 1,\n        ]);\n    }\n}\n"
  },
  {
    "path": "tests/database/factories/DepartmentFactory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Database\\Factories;\n\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\Department;\n\nclass DepartmentFactory extends Factory\n{\n    protected $model = Department::class;\n\n    public function definition()\n    {\n        return [\n            'name' => $this->faker->company,\n        ];\n    }\n\n    public function active()\n    {\n        return $this->state([\n            'active' => 1,\n        ]);\n    }\n\n    public function flagship()\n    {\n        return $this->state([\n            'flagship' => 1,\n        ]);\n    }\n\n    public function mediumSized()\n    {\n        return $this\n            ->with(1, 'manager')\n            ->with(4, 'employees');\n    }\n}\n"
  },
  {
    "path": "tests/database/factories/UserFactory.php",
    "content": "<?php\n\nnamespace Makeable\\LaravelFactory\\Tests\\Database\\Factories;\n\nuse Makeable\\LaravelFactory\\Factory;\nuse Makeable\\LaravelFactory\\Tests\\Stubs\\User;\n\nclass UserFactory extends Factory\n{\n    protected $model = User::class;\n\n    public function definition()\n    {\n        return [\n            'name' => $this->faker->name,\n            'email' => $this->faker->unique()->safeEmail,\n            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password\n        ];\n    }\n}\n"
  },
  {
    "path": "tests/database/migrations/2018_04_27_000000_create_test_tables.php",
    "content": "<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreateTestTables extends Migration\n{\n    /**\n     * Run the migrations.\n     */\n    public function up()\n    {\n        $this->createTables('primary');\n        $this->createTables('secondary');\n    }\n\n    protected function createTables($connection)\n    {\n        Schema::connection($connection)->create('users', function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->string('email')->unique();\n            $table->timestamp('email_verified_at')->nullable();\n            $table->string('password');\n            $table->string('remember_token', 100)->nullable();\n            $table->timestamps();\n        });\n\n        Schema::connection($connection)->create('companies', function (Blueprint $table) {\n            $table->increments('id');\n            $table->unsignedInteger('owner_id')->nullable();\n            $table->string('name');\n            $table->text('tags')->nullable();\n            $table->timestamps();\n        });\n\n        Schema::connection($connection)->create('customers', function (Blueprint $table) {\n            $table->increments('id');\n            $table->unsignedInteger('company_id')->nullable();\n            $table->integer('satisfaction')->nullable();\n            $table->timestamps();\n        });\n\n        Schema::connection($connection)->create('departments', function (Blueprint $table) {\n            $table->increments('id');\n            $table->unsignedInteger('company_id')->nullable();\n            $table->unsignedInteger('manager_id')->nullable();\n            $table->tinyInteger('active')->default(0);\n            $table->tinyInteger('flagship')->default(0);\n            $table->string('name');\n            $table->timestamps();\n        });\n\n        Schema::connection($connection)->create('employees', function (Blueprint $table) {\n            $table->increments('id');\n            $table->unsignedInteger('department_id');\n            $table->unsignedInteger('user_id');\n            $table->timestamp('started_at')->nullable();\n            $table->timestamps();\n        });\n\n        Schema::connection($connection)->create('images', function (Blueprint $table) {\n            $table->increments('id');\n            $table->morphs('imageable');\n            $table->timestamps();\n        });\n\n        Schema::connection($connection)->dropIfExists('users');\n        Schema::connection($connection)->create('users', function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->string('email')->unique();\n            $table->string('password');\n            $table->timestamp('email_verified_at')->nullable();\n            $table->rememberToken();\n            $table->timestamps();\n        });\n    }\n}\n"
  }
]