[
  {
    "path": ".all-contributorsrc",
    "content": "{\n  \"files\": [\n    \"README.md\"\n  ],\n  \"imageSize\": 100,\n  \"commit\": false,\n  \"contributors\": [\n    {\n      \"login\": \"RafaelFerreiraTVD\",\n      \"name\": \"Rafael Ferreira\",\n      \"avatar_url\": \"https://avatars1.githubusercontent.com/u/15105462?v=4\",\n      \"profile\": \"http://www.xgeeks.io\",\n      \"contributions\": [\n        \"doc\"\n      ]\n    },\n    {\n      \"login\": \"tiagomichaelsousa\",\n      \"name\": \"tiagomichaelsousa\",\n      \"avatar_url\": \"https://avatars1.githubusercontent.com/u/28356381?v=4\",\n      \"profile\": \"https://github.com/tiagomichaelsousa\",\n      \"contributions\": [\n        \"code\",\n        \"doc\",\n        \"content\",\n        \"review\"\n      ]\n    },\n    {\n      \"login\": \"white-hyena\",\n      \"name\": \"White Hyena\",\n      \"avatar_url\": \"https://avatars3.githubusercontent.com/u/62600397?v=4\",\n      \"profile\": \"https://github.com/white-hyena\",\n      \"contributions\": [\n        \"code\",\n        \"content\"\n      ]\n    },\n    {\n      \"login\": \"pkboom\",\n      \"name\": \"Keunbae Park\",\n      \"avatar_url\": \"https://avatars2.githubusercontent.com/u/13960169?v=4\",\n      \"profile\": \"https://github.com/pkboom\",\n      \"contributions\": [\n        \"code\",\n        \"content\"\n      ]\n    }\n  ],\n  \"contributorsPerLine\": 7,\n  \"projectName\": \"LaravelResources\",\n  \"projectOwner\": \"tiagomichaelsousa\",\n  \"repoType\": \"github\",\n  \"repoHost\": \"https://github.com\",\n  \"skipCi\": true\n}\n"
  },
  {
    "path": ".github/workflows/composer-normalize.yml",
    "content": "name: Composer Normalize\n\non:\n    push:\n        paths:\n            - \"composer.json\"\n\njobs:\n    normalize:\n        runs-on: ubuntu-latest\n        steps:\n            - name: Git checkout\n              uses: actions/checkout@v3\n\n            - name: normalize composer.json\n              run: |\n                  composer global require ergebnis/composer-normalize\n                  composer normalize\n            - uses: stefanzweifel/git-auto-commit-action@v4\n              with:\n                  commit_message: Normalize composer.json\n"
  },
  {
    "path": ".github/workflows/run-tests.yml",
    "content": "name: CI\n\non: ['push', 'pull_request']\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    strategy:\n      fail-fast: false\n      matrix:\n        php:\n          - '8.0'\n          - '8.1'\n          - '8.2'\n        laravel:\n          - 8.*\n          - 9.*\n          - 10.*\n        prefer:\n          - 'prefer-stable'\n        include:\n          - laravel: 8.*\n            testbench: 6.*\n          - laravel: 9.*\n            testbench: 7.*\n          - laravel: 10.*\n            testbench: 8.*\n        exclude:\n          - laravel: 10.*\n            php: 8.0\n\n    name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} --${{ matrix.prefer }}\n\n    steps:\n      - uses: actions/checkout@v2.4.0\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, yaml\n          coverage: pcov\n\n      - uses: actions/cache@v2.1.7\n        name: Cache dependencies\n        with:\n          path: ~/.composer/cache/files\n          key: composer-php-${{ matrix.php }}-${{ matrix.laravel }}-${{ matrix.prefer }}-${{ hashFiles('composer.json') }}\n\n      - name: Install dependencies\n        run: |\n          composer require \"laravel/framework:${{ matrix.laravel }}\" \"orchestra/testbench:${{ matrix.testbench }}\" --no-interaction --no-update\n          composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest\n\n      - name: Run tests\n        run: |\n          vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml\n"
  },
  {
    "path": ".gitignore",
    "content": "/.phpunit.result.cache\n/build/\n/vendor/\n/tests/temp\ncomposer.lock\ncomposer.phar\n.idea\n/report\n.DS_Store\ncoverage.clover\n"
  },
  {
    "path": ".styleci.yml",
    "content": "preset: laravel\n\nfinder:\n    name:\n        - \"*.php\"\n"
  },
  {
    "path": "README.md",
    "content": "# Laravel Resources\n\n<p align=\"center\">\n    <img src=\"./docs/demo.gif\" alt=\"Laravel Resources Demo\" width=\"480\">\n</p>\n\n<p align=\"center\">\n    <img src=\"https://img.shields.io/packagist/v/tiagomichaelsousa/laravelresources.svg?style=flat-square\" alt=\"Packagist Version\">\n    <img src=\"https://img.shields.io/packagist/dt/tiagomichaelsousa/laravelresources.svg?style=flat-square\" alt=\"Packagist Downloads\">\n    <img src=\"https://img.shields.io/travis/tiagomichaelsousa/laravelresources/master.svg?style=flat-square\" alt=\"Build Status\">\n    <img src=\"https://github.styleci.io/repos/236964942/shield\" alt=\"Style Status\">\n    <img src=\"https://poser.pugx.org/tiagomichaelsousa/laravelresources/license?format=flat-square\" alt=\"Licence\">\n    <img src=\"https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square\" alt=\"All Contributors\">\n    <img src=\"https://api.codacy.com/project/badge/Grade/8c5fafbbbf524b4db771a7bb1c55bb39\" alt=\"Code Quality\">\n    <img src=\"https://api.codacy.com/project/badge/Coverage/8c5fafbbbf524b4db771a7bb1c55bb39\" alt=\"Code Coverage\">\n\n</p>\n\n---\n\nLaravel Resources is a speed-up development package that allows you to create a boilerplate for Laravel apps with a default API structure.\n\n## Versions\n\n| Laravel  | Laravel Resources |\n|----------| ----------------- |\n| 7.x      | v1.7              |\n| 8.x      | v2.x              |\n| 9.x      | v2.x              |\n| 10.x     | v3.x              |\n\n## Installation\n\nVia Composer\n\n```bash\n$ composer require tiagomichaelsousa/laravelresources --dev\n```\n\n## Usage\n\nCreate the resources\n\n```bash\n$ php artisan resources:create <model>\n```\n\nThis command will create the Controller, the Request, the Policy, the API Resource and Collection and will also add the default routes for the API.\n\nPublish configuration file\n\n```bash\n$ php artisan vendor:publish --provider=\"tiagomichaelsousa\\LaravelResources\\LaravelResourcesServiceProvider\" --tag=\"config\"\n```\n\n**Notes:**\n\n-   This package is fully configurable. You can change all the namespaces for the resources that will be created in the config file.\n-   Don't forget to edit the request file in order to add your default validation for the model.\n-   Don't forget to edit the policy file in order to fulfill your app business logic.\n\n## Change log\n\nPlease see the [changelog](changelog.md) for more information on what has changed recently.\n\n## Testing\n\n```bash\n$ composer test\n```\n\n### With test coverage\n\n```bash\n$ composer test-report\n```\n\n## Contributing\n\nPlease see [contributing.md](contributing.md) for details and a todolist.\n\n## Security\n\nIf you discover any security related issues, please email the [author](mailto:tiagomichaelsousa@gmail.com) instead of using the issue tracker.\n\n## Credits\n\n-   [@tiagomichaelsousa][link-author]\n-   [All Contributors][link-contributors]\n\n## License\n\nLicense MIT. Please see the [license file](license.md) for more information.\n\n## Code Of Conduct\n\nPlease see the [code of conduct](code_of_conduct.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/tiagomichaelsousa/laravelresources.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/tiagomichaelsousa/laravelresources.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/tiagomichaelsousa/laravelresources/master.svg?style=flat-square\n[ico-styleci]: https://github.styleci.io/repos/236964942/shield\n[link-packagist]: https://packagist.org/packages/tiagomichaelsousa/laravelresources\n[link-downloads]: https://packagist.org/packages/tiagomichaelsousa/laravelresources\n[link-travis]: https://travis-ci.org/tiagomichaelsousa/laravelresources\n[link-styleci]: https://styleci.io/repos/236964942\n[link-author]: https://github.com/tiagomichaelsousa\n[link-contributors]: ../../contributors\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n  <tr>\n    <td align=\"center\"><a href=\"http://www.xgeeks.io\"><img src=\"https://avatars1.githubusercontent.com/u/15105462?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Rafael Ferreira</b></sub></a><br /><a href=\"https://github.com/tiagomichaelsousa/LaravelResources/commits?author=RafaelFerreiraTVD\" title=\"Documentation\">📖</a></td>\n    <td align=\"center\"><a href=\"https://github.com/tiagomichaelsousa\"><img src=\"https://avatars1.githubusercontent.com/u/28356381?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>tiagomichaelsousa</b></sub></a><br /><a href=\"https://github.com/tiagomichaelsousa/LaravelResources/commits?author=tiagomichaelsousa\" title=\"Code\">💻</a> <a href=\"https://github.com/tiagomichaelsousa/LaravelResources/commits?author=tiagomichaelsousa\" title=\"Documentation\">📖</a> <a href=\"#content-tiagomichaelsousa\" title=\"Content\">🖋</a> <a href=\"https://github.com/tiagomichaelsousa/LaravelResources/pulls?q=is%3Apr+reviewed-by%3Atiagomichaelsousa\" title=\"Reviewed Pull Requests\">👀</a></td>\n    <td align=\"center\"><a href=\"https://github.com/white-hyena\"><img src=\"https://avatars3.githubusercontent.com/u/62600397?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>White Hyena</b></sub></a><br /><a href=\"https://github.com/tiagomichaelsousa/LaravelResources/commits?author=white-hyena\" title=\"Code\">💻</a> <a href=\"#content-white-hyena\" title=\"Content\">🖋</a></td>\n    <td align=\"center\"><a href=\"https://github.com/pkboom\"><img src=\"https://avatars2.githubusercontent.com/u/13960169?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Keunbae Park</b></sub></a><br /><a href=\"https://github.com/tiagomichaelsousa/LaravelResources/commits?author=pkboom\" title=\"Code\">💻</a> <a href=\"#content-pkboom\" title=\"Content\">🖋</a></td>\n  </tr>\n</table>\n\n<!-- markdownlint-enable -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n"
  },
  {
    "path": "changelog.md",
    "content": "# Changelog\n\nAll notable changes to `LaravelResources` will be documented in this file.\n\n## Version 1.0\n\n### Added\n- Everything\n"
  },
  {
    "path": "code_of_conduct.md",
    "content": "# Code Of Conductd\n\nThis code of conduct is derived from the Ruby code of conduct. Any violations of the code of conduct may be reported to [author](tiagomichaelsousa@gmail.com).\n\n- Participants will be tolerant of opposing views.\n- Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.\n- When interpreting the words and actions of others, participants should always assume good intentions.\n- Behavior which can be reasonably considered harassment will not be tolerated.\n"
  },
  {
    "path": "composer.json",
    "content": "{\n  \"name\": \"tiagomichaelsousa/laravelresources\",\n  \"description\": \"Laravel Resources is a speed-up development package that allows you to create a boilerplate for Laravel apps with a default API structure.\",\n  \"license\": \"MIT\",\n  \"authors\": [\n    {\n      \"name\": \"tiagomichaelsousa\",\n      \"email\": \"tiagomichaelsousa@gmail.com\",\n      \"homepage\": \"https://github.com/tiagomichaelsousa\",\n      \"role\": \"Developer\"\n    }\n  ],\n  \"homepage\": \"https://github.com/tiagomichaelsousa/laravelresources\",\n  \"keywords\": [\n    \"Laravel\",\n    \"LaravelResources\",\n    \"laravelresources\",\n    \"laravel-resources\"\n  ],\n  \"require\": {\n    \"illuminate/support\": \"^7.0|^8.0|^9.0|^10.0\"\n  },\n  \"require-dev\": {\n    \"phpunit/phpunit\": \"^8.5|^9.0|^10.0\",\n    \"mockery/mockery\": \"^1.3.1\",\n    \"sempro/phpunit-pretty-print\": \"^1.4\",\n    \"orchestra/testbench\": \"^8.5\"\n  },\n  \"autoload\": {\n    \"files\": [\n      \"src/Helpers/helpers.php\"\n    ],\n    \"psr-4\": {\n      \"tiagomichaelsousa\\\\LaravelResources\\\\\": \"src/\"\n    }\n  },\n  \"autoload-dev\": {\n    \"psr-4\": {\n      \"tiagomichaelsousa\\\\LaravelResources\\\\Tests\\\\\": \"tests\"\n    }\n  },\n  \"scripts\": {\n    \"test\": \"vendor/bin/phpunit\",\n    \"test-report\": \"vendor/bin/phpunit --coverage-html report\"\n  },\n  \"extra\": {\n    \"laravel\": {\n      \"providers\": [\n        \"tiagomichaelsousa\\\\LaravelResources\\\\LaravelResourcesServiceProvider\"\n      ],\n      \"aliases\": {\n        \"LaravelResources\": \"tiagomichaelsousa\\\\LaravelResources\\\\Facades\\\\LaravelResources\"\n      }\n    }\n  }\n}\n"
  },
  {
    "path": "config/laravel-resources.php",
    "content": "<?php\n\nreturn [\n\n    /*\n    |--------------------------------------------------------------------------\n    | Controller configs\n    |--------------------------------------------------------------------------\n    |\n    | This values are used when a new controller is created.\n    | If you change the namespace, it will automatically create the controller in the folder base path.\n    | The suffix and prefix are variables that can be edited to change the class name for the controller\n    |\n    */\n    'controllers' => [\n        'namespace' => 'App\\Http\\Controllers',\n        'suffix' => 'API',\n        'prefix' => null,\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Resources configs\n    |--------------------------------------------------------------------------\n    |\n    | This values are used when a new resource is created.\n    | If you change the namespace, it will automatically create the resource in the folder base path.\n    | The suffix and prefix are variables that can be edited to change the class name for the controller.\n    | When you create a resource you can also create a collection that will inherit the data from the resource.\n    | The collection class will also have the possibility to define the suffix and prefix for the class name.\n    |\n    */\n    'resources' => [\n        'namespace' => 'App\\Http\\Resources',\n        'suffix' => null,\n        'prefix' => null,\n    ],\n\n    'collections' => [\n        'namespace' => 'App\\Http\\Resources\\Collections',\n        'suffix' => null,\n        'prefix' => null,\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Resources configs\n    |--------------------------------------------------------------------------\n    |\n    | This values are used when a new resource is created.\n    | If you change the namespace, it will automatically create the resource in the folder base path.\n    | The suffix and prefix are variables that can be edited to change the class name for the controller.\n    | When you create a resource you can also create a collection that will inherit the data from the resource.\n    | The collection class will also have the possibility to define the suffix and prefix for the class name.\n    |\n    */\n    'requests' => [\n        'namespace' => 'App\\Http\\Requests',\n        'suffix' => null,\n        'prefix' => null,\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Policies configs\n    |--------------------------------------------------------------------------\n    |\n    | This values are used when a new policy is created.\n    | If you change the namespace, it will automatically create the resource in the folder base path.\n    | The suffix and prefix are variables that can be edited to change the class name for the policy.\n    |\n    */\n    'policies' => [\n        'namespace' => 'App\\Policies',\n        'suffix' => null,\n        'prefix' => null,\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Model configs\n    |--------------------------------------------------------------------------\n    |\n    | This config is used to fetch the models from the namespace.\n    | Many projects change the path for the models to /app/models and thats the mainly reason\n    | for the usage of this config value.\n    |\n    */\n    'models' => [\n        'namespace' => 'App\\Models',\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Routes configs\n    |--------------------------------------------------------------------------\n    |\n    | This config is used set the path and the filename where the stubs for the routes\n    | will be added.\n    |\n    */\n    'routes' => [\n        'path' => 'routes',\n        'filename' => 'api.php',\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Database configs\n    |--------------------------------------------------------------------------\n    |\n    | This config is used to set the path for the migrations, factories and seeds\n    | This configs should not be edited if you dont change the laravel mapping folders\n    |\n    */\n    'database' => [\n        'migrations' => 'database/migrations',\n        'factories' => 'database/factories',\n        'seeds' => 'database/seeders',\n    ],\n];\n"
  },
  {
    "path": "contributing.md",
    "content": "# Contributing\n\nContributions are welcome and will be fully credited.\n\nContributions are accepted via Pull Requests on [Github](https://github.com/tiagomichaelsousa/laravelresources).\n\n# Things you could do\n\nIf you want to contribute but do not know where to start, this list provides some starting points.\n\n- Set up TravisCI, StyleCI\n- Write a comprehensive ReadMe\n\n## Pull Requests\n\n- **Add tests!** - Your patch won't be accepted if it doesn't have tests.\n\n- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.\n\n- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.\n\n- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.\n\n- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.\n\n**Happy coding**!\n"
  },
  {
    "path": "license.md",
    "content": "# The license\n\nCopyright 2020 [@tiagomichaelsousa](https://github.com/tiagomichaelsousa)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" bootstrap=\"vendor/autoload.php\" backupGlobals=\"false\" backupStaticAttributes=\"false\" colors=\"true\" verbose=\"true\" convertErrorsToExceptions=\"true\" convertNoticesToExceptions=\"true\" convertWarningsToExceptions=\"true\" processIsolation=\"false\" stopOnFailure=\"false\" xsi:noNamespaceSchemaLocation=\"https://schema.phpunit.de/9.3/phpunit.xsd\">\n  <coverage>\n    <include>\n      <directory>src/</directory>\n    </include>\n  </coverage>\n  <testsuites>\n    <testsuite name=\"Laravel Resources Test Suite\">\n      <directory>tests/</directory>\n    </testsuite>\n  </testsuites>\n</phpunit>\n"
  },
  {
    "path": "src/Commands/ResourceCommand.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Commands;\n\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Support\\Facades\\File;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\CollectionGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\ControllerGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\FactoryGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\MigrationGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\ModelGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\PolicyGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\RequestGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\ResourceGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\RouteGenerator;\nuse tiagomichaelsousa\\LaravelResources\\Generators\\SeederGenerator;\n\nclass ResourceCommand extends Command\n{\n    /**\n     * The resources that can be created.\n     *\n     * @var array\n     */\n    private $resources = [\n        ResourceGenerator::class,\n        CollectionGenerator::class,\n        RequestGenerator::class,\n        PolicyGenerator::class,\n        ControllerGenerator::class,\n        RouteGenerator::class,\n    ];\n\n    /**\n     * The resources that can be created if the model does not exists.\n     *\n     * @var array\n     */\n    private $modelResources = [\n        'migration' => MigrationGenerator::class,\n        'factory' => FactoryGenerator::class,\n        'seeder' => SeederGenerator::class,\n    ];\n\n    /**\n     * The model name for the resources.\n     *\n     * @var string\n     */\n    private $model;\n\n    /**\n     * The name and signature of the console command.\n     *\n     * @var string\n     */\n    protected $signature = 'resources:create\n                            {model : The model for the resource}';\n\n    /**\n     * The console command description.\n     *\n     * @var string\n     */\n    protected $description = 'This command will allow you to create all resources that you need for a clean api code structure';\n\n    /**\n     * Verify if the model exists to create the resources.\n     *\n     * @return bool\n     */\n    private function modelExists()\n    {\n        return File::exists(base_path(lcfirst(str_replace('\\\\', '/', config('laravel-resources.models.namespace')))).\"/{$this->model}.php\");\n    }\n\n    /**\n     * Create the model if does not exists.\n     *\n     * @return void\n     */\n    private function createModelResources()\n    {\n        foreach ($this->modelResources as $resource => $generator) {\n            if ($this->confirm(\"Should I create the {$resource} for {$this->model}?\", true)) {\n                array_push($this->resources, $generator);\n            }\n        }\n    }\n\n    /**\n     * Create the resources for the model.\n     *\n     * @return void\n     */\n    private function createResources()\n    {\n        $this->info('Creating '.count($this->resources).' resources ...');\n        $this->line('');\n\n        $bar = $this->getOutput()->createProgressBar(count($this->resources));\n\n        foreach ($this->resources as $resource) {\n            (new $resource($this->model))->handle();\n            $bar->advance();\n        }\n\n        $bar->finish();\n        $this->line('');\n\n        $this->line('');\n\n        $this->info('🚀 Resources created successfully 🚀');\n        $this->line('');\n\n        exec('composer dumpautoload');\n    }\n\n    /**\n     * Execute the console command.\n     *\n     * @return mixed\n     */\n    public function handle()\n    {\n        $this->info('Checking if the model exists ...');\n\n        $this->model = $this->argument('model');\n\n        if (! $this->modelExists()) {\n            $this->info(\"The model {$this->model} does not exists.\");\n\n            if (! $this->confirm('Should I create it?', true)) {\n                return;\n            }\n\n            (new ModelGenerator($this->model))->handle();\n\n            $this->createModelResources();\n        }\n\n        $this->createResources();\n    }\n}\n"
  },
  {
    "path": "src/Exceptions/File.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Exceptions;\n\nuse Exception;\n\nclass File extends Exception\n{\n    public static function alreadyExistsInDirectory(string $path)\n    {\n        return new static(\"The file already exists in the path $path\");\n    }\n\n    public static function doesNotExists(string $path)\n    {\n        return new static(\"The file doesn't exists in the path $path\");\n    }\n}\n"
  },
  {
    "path": "src/Generators/AbstractGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\nuse tiagomichaelsousa\\LaravelResources\\Exceptions\\File as FileException;\n\nabstract class AbstractGenerator implements Generator\n{\n    /**\n     * The model for that will be used in the policy.\n     *\n     * @var string\n     */\n    protected $model;\n\n    /**\n     * Create a new command instance.\n     *\n     * @return void\n     */\n    public function __construct($model)\n    {\n        $this->model = $model;\n    }\n\n    /**\n     * Verify if the directory and create one if it doesn't.\n     *\n     * @return bool\n     */\n    public function directoryExists($path)\n    {\n        return (bool) File::isDirectory($path) ?: make_directory($path);\n    }\n\n    /**\n     * Verify if the resource already exists.\n     *\n     * @return mixed|\\tiagomichaelsousa\\LaravelResources\\Exceptions\\File\n     */\n    public function fileAlreadyExists($path)\n    {\n        if (File::exists($path)) {\n            throw FileException::alreadyExistsInDirectory($path);\n        }\n    }\n\n    /**\n     * Generate the file name.\n     *\n     * @return string\n     */\n    public function fileName()\n    {\n        return \"{$this->className()}.php\";\n    }\n}\n"
  },
  {
    "path": "src/Generators/CollectionGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass CollectionGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the collection.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/resources/api.collection.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{NAMESPACE}}' => config('laravel-resources.collections.namespace'),\n            '{{CLASS_NAME}}' => \"{$this->className()}\",\n            '{{RESOURCE_NAMESPACE}}' => config('laravel-resources.resources.namespace'),\n            '{{RESOURCE_CLASS_NAME}}' =>  create_class_name($this->model, ResourceGenerator::class),\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return create_class_name($this->model, self::class);\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.collections.namespace');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/ControllerGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Arr;\nuse Illuminate\\Support\\Facades\\File;\n\nclass ControllerGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the controller.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/controllers/controller.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge(\n            [\n                '{{NAMESPACE}}' => config('laravel-resources.controllers.namespace'),\n                '{{CONTROLLER_NAMESPACE}}' => config('laravel-resources.controllers.namespace'),\n                '{{CONTROLLER_NAME}}' => \"{$this->className()}\",\n                '{{RESOURCE_NAMESPACE}}' => config('laravel-resources.resources.namespace').'\\\\'.create_class_name($this->model, ResourceGenerator::class),\n                '{{RESOURCE_COLLECTION_NAMESPACE}}' => config('laravel-resources.collections.namespace').'\\\\'.create_class_name($this->model, CollectionGenerator::class),\n                '{{MODEL_CLASS}}' => \"{$this->model}\",\n            ],\n            $this->modelReplacements(),\n            $this->requestReplacements(),\n            $this->methodsReplacements()\n        );\n    }\n\n    /**\n     * Get the replacements for the stub methods.\n     *\n     * @return array\n     */\n    private function methodsReplacements()\n    {\n        $methods = [];\n\n        foreach (['index', 'store', 'show', 'update', 'destroy'] as $method) {\n            $stub = File::get(__DIR__.\"/../stubs/controllers/controller.method.{$method}.stub\");\n\n            $replaces = [\n                '{{CLASS_NAME}}' => $this->model,\n                '{{RESOURCE_NAME}}' => $method === 'index' ? create_class_name($this->model, CollectionGenerator::class) : create_class_name($this->model, ResourceGenerator::class),\n                '{{CLASS_VARIABLE}}' => lcfirst($this->model),\n            ];\n\n            $methodStubName = strtoupper($method);\n\n            array_push($methods, [\"{{{$methodStubName}_METHOD}}\" => str_replace(array_keys($replaces), array_values($replaces), $stub)]);\n        }\n\n        return Arr::collapse($methods);\n    }\n\n    /**\n     * Get the replacements for the current model.\n     *\n     * @return array\n     */\n    public function modelReplacements()\n    {\n        return [\n            '{{MODEL_CLASS}}' => $this->model,\n            '{{MODEL_VARIABLE}}' => lcfirst($this->model),\n            '{{MODEL_NAMESPACE}}' => config('laravel-resources.models.namespace').\"\\\\{$this->model}\",\n        ];\n    }\n\n    /**\n     * Get the replacements for the current request of the current model.\n     *\n     * @return array\n     */\n    public function requestReplacements()\n    {\n        $requestClass = create_class_name($this->model, RequestGenerator::class);\n\n        return [\n            '{{REQUEST_CLASS}}' =>  $requestClass,\n            '{{REQUEST_NAMESPACE}}' => config('laravel-resources.requests.namespace').\"\\\\{$requestClass}\",\n        ];\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return create_class_name($this->model, self::class);\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.controllers.namespace');\n        $directory = namespace_path($namespace);\n\n        $path = \"{$directory}/{$this->filename()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/FactoryGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass FactoryGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the policy.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/factories/factory.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{MODEL_NAMESPACE}}' => config('laravel-resources.models.namespace'),\n            '{{MODEL_NAME}}' => $this->model,\n            '{{CLASS_NAME}}' => $this->className(),\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return \"{$this->model}Factory\";\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.database.factories');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/Generator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\ninterface Generator\n{\n    public function getStub();\n\n    public function replacements();\n\n    public function fileAlreadyExists($path);\n\n    public function directoryExists($path);\n\n    public function className();\n\n    public function fileName();\n\n    public function handle();\n}\n"
  },
  {
    "path": "src/Generators/MigrationGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\File;\nuse Illuminate\\Support\\Str;\n\nclass MigrationGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the policy.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/migrations/migration.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{CLASS_NAME}}' => $this->className(),\n            '{{TABLE_NAME}}' => Str::lower(Str::snake(Str::plural($this->model))),\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        $name = Str::plural($this->model);\n\n        return \"Create{$name}Table\";\n    }\n\n    /**\n     * Generate the file name.\n     *\n     * @return string\n     */\n    public function fileName()\n    {\n        $date = Carbon::now()->format('Y_m_d_Hms');\n        $name = Str::lower(Str::snake($this->className()));\n\n        return \"{$date}_{$name}.php\";\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.database.migrations');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/ModelGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass ModelGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the policy.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/models/model.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{NAMESPACE}}' => config('laravel-resources.models.namespace'),\n            '{{CLASS_NAME}}' => $this->model,\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return ucfirst($this->model);\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.models.namespace');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/PolicyGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass PolicyGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the policy.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/policies/api.policies.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{NAMESPACE}}' => config('laravel-resources.policies.namespace'),\n            '{{CLASS_NAME}}' => \"{$this->className()}\",\n            '{{MODEL_NAMESPACE}}' => config('laravel-resources.models.namespace'),\n            '{{MODEL_NAME}}' => config('laravel-resources.models.namespace'),\n            '{{MODEL_CLASS}}' => $this->model,\n            '{{MODEL_VARIABLE}}' => lcfirst($this->model),\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return create_class_name($this->model, self::class);\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.policies.namespace');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/RequestGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass RequestGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the request.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/requests/api.request.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{NAMESPACE}}' => config('laravel-resources.requests.namespace'),\n            '{{CLASS_NAME}}' => $this->className(),\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return create_class_name($this->model, self::class);\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.requests.namespace');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->filename()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/ResourceGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass ResourceGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the request.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/resources/api.resource.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{NAMESPACE}}' => config('laravel-resources.resources.namespace'),\n            '{{CLASS_NAME}}' => \"{$this->className()}\",\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return create_class_name($this->model, self::class);\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.resources.namespace');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->filename()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Generators/RouteGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\nuse Illuminate\\Support\\Str;\nuse tiagomichaelsousa\\LaravelResources\\Exceptions\\File as FileException;\n\nclass RouteGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the request.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/routes/api.routes.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{MODEL_NAME}}' => $this->model,\n            '{{MODEL_VARIABLE}}' => lcfirst($this->model),\n            '{{CONTROLLER_NAME}}' => $this->generateControllerName(),\n            '{{ROUTE_NAME}}' => Str::plural(Str::kebab($this->model)),\n        ]);\n    }\n\n    /**\n     * Verify if the resource already exists.\n     *\n     * @return mixed|\\tiagomichaelsousa\\LaravelResources\\Exceptions\\File\n     */\n    public function fileAlreadyExists($path)\n    {\n        if (File::missing($path)) {\n            throw FileException::doesNotExists($path);\n        }\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        return 'Route';\n    }\n\n    /**\n     * Generate the file name.\n     *\n     * @return string\n     */\n    public function fileName()\n    {\n        return config('laravel-resources.routes.filename');\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $path = config('laravel-resources.routes.path');\n        $directory = base_path($path);\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        $controllerNamespace = config('laravel-resources.controllers.namespace');\n        $controllerImport = \"use {$controllerNamespace}\\\\{$this->generateControllerName()}\";\n        $content = str_replace(\"<?php\\n\", \"<?php\\n\\n$controllerImport;\", file_get_contents($path));\n        file_put_contents($path, $content);\n\n        file_put_contents($path, [$stub, PHP_EOL], FILE_APPEND | FILE_USE_INCLUDE_PATH);\n    }\n\n    /**\n     * Generates the controller name.\n     *\n     * @return string\n     */\n    private function generateControllerName()\n    {\n        return create_class_name($this->model, 'ControllerGenerator');\n    }\n}\n"
  },
  {
    "path": "src/Generators/SeederGenerator.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Generators;\n\nuse Illuminate\\Support\\Facades\\File;\nuse Illuminate\\Support\\Str;\n\nclass SeederGenerator extends AbstractGenerator\n{\n    /**\n     * Get the Stub for the policy.\n     *\n     * @return string\n     */\n    public function getStub()\n    {\n        return File::get(__DIR__.'/../stubs/seeds/seed.stub');\n    }\n\n    /**\n     * Get the replacements for the stub.\n     *\n     * @return array\n     */\n    public function replacements()\n    {\n        return array_merge([\n            '{{MODEL_NAMESPACE}}' => config('laravel-resources.models.namespace'),\n            '{{MODEL_NAME}}' => $this->model,\n            '{{MODEL_PLURAL}}' => Str::plural($this->model),\n            '{{CLASS_NAME}}' => $this->className(),\n        ]);\n    }\n\n    /**\n     * Generate the class name.\n     *\n     * @return string\n     */\n    public function className()\n    {\n        $plural = Str::plural($this->model);\n\n        return \"{$plural}TableSeeder\";\n    }\n\n    /**\n     * Handle the resource creation.\n     *\n     * @return void\n     */\n    public function handle()\n    {\n        $namespace = config('laravel-resources.database.seeds');\n        $directory = base_path(lcfirst(str_replace('\\\\', '/', $namespace)));\n        $path = \"{$directory}/{$this->fileName()}\";\n\n        $this->fileAlreadyExists($path);\n\n        $replaces = $this->replacements($this->model);\n        $stub = str_replace(array_keys($replaces), array_values($replaces), $this->getStub());\n\n        $this->directoryExists($directory);\n\n        file_put_contents($path, $stub);\n    }\n}\n"
  },
  {
    "path": "src/Helpers/helpers.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\File;\nuse Illuminate\\Support\\Str;\n\nif (! function_exists('make_directory')) {\n    /**\n     * Create recursive directory.\n     *\n     * @param  string  $path\n     * @param  string  $mode\n     * @param  bool  $recursive\n     * @param  bool  $force\n     * @return bool\n     */\n    function make_directory($path, int $mode = 0755, bool $recursive = true, bool $force = false)\n    {\n        return File::makeDirectory($path, $mode, $recursive, $force);\n    }\n}\n\nif (! function_exists('namespace_path')) {\n    /**\n     * Receive a namespace and convert it to a path.\n     *\n     * @param  string  $path\n     * @return string\n     */\n    function namespace_path($path)\n    {\n        return base_path(lcfirst(str_replace('\\\\', '/', $path)));\n    }\n}\n\nif (! function_exists('create_class_name')) {\n    /**\n     * Receive a classname for a resource.\n     *\n     * @param  string  $path\n     * @return string\n     */\n    function create_class_name($model, $resource)\n    {\n        $resource = Str::before(class_basename($resource), 'Generator');\n        $configKey = Str::plural(strtolower($resource));\n        $className = \"{$model}{$resource}\";\n\n        if (! is_null($suffix = config(\"laravel-resources.{$configKey}.suffix\"))) {\n            $className = Str::finish($className, $suffix);\n        }\n\n        if (! is_null($prefix = config(\"laravel-resources.{$configKey}.prefix\"))) {\n            $className = Str::start($className, $prefix);\n        }\n\n        return $className;\n    }\n}\n"
  },
  {
    "path": "src/LaravelResourcesServiceProvider.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass LaravelResourcesServiceProvider extends ServiceProvider\n{\n    /**\n     * The console commands.\n     *\n     * @var array\n     */\n    protected $commands = [\n        'tiagomichaelsousa\\LaravelResources\\Commands\\ResourceCommand',\n    ];\n\n    /**\n     * Perform post-registration booting of services.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        // Publishing is only necessary when using the CLI.\n        if ($this->app->runningInConsole()) {\n            $this->bootForConsole();\n        }\n    }\n\n    /**\n     * Register any package services.\n     *\n     * @return void\n     */\n    public function register()\n    {\n        $this->mergeConfigFrom(__DIR__.'/../config/laravel-resources.php', 'laravel-resources');\n    }\n\n    /**\n     * Console-specific booting.\n     *\n     * @return void\n     */\n    protected function bootForConsole()\n    {\n        // Publishing the configuration file.\n        $this->publishes([\n            __DIR__.'/../config/laravel-resources.php' => app()->basePath().'/config/laravel-resources.php',\n        ], 'config');\n\n        // Registering package commands.\n        $this->commands($this->commands);\n    }\n}\n"
  },
  {
    "path": "src/stubs/controllers/controller.method.destroy.stub",
    "content": "${{CLASS_VARIABLE}}->delete();\n\n        return new {{RESOURCE_NAME}}(${{CLASS_VARIABLE}});\n"
  },
  {
    "path": "src/stubs/controllers/controller.method.index.stub",
    "content": "${{CLASS_VARIABLE}} = {{CLASS_NAME}}::all();\n\n        return new {{RESOURCE_NAME}}(${{CLASS_VARIABLE}});\n"
  },
  {
    "path": "src/stubs/controllers/controller.method.show.stub",
    "content": "return new {{RESOURCE_NAME}}(${{CLASS_VARIABLE}});\n"
  },
  {
    "path": "src/stubs/controllers/controller.method.store.stub",
    "content": "${{CLASS_VARIABLE}} = {{CLASS_NAME}}::create($request->validated());\n\n        return new {{RESOURCE_NAME}}(${{CLASS_VARIABLE}});\n"
  },
  {
    "path": "src/stubs/controllers/controller.method.update.stub",
    "content": "${{CLASS_VARIABLE}}->update($request->validated());\n\n        return new {{RESOURCE_NAME}}(${{CLASS_VARIABLE}});\n"
  },
  {
    "path": "src/stubs/controllers/controller.stub",
    "content": "<?php\n\nnamespace {{NAMESPACE}};\n\nuse {{MODEL_NAMESPACE}};\nuse {{RESOURCE_NAMESPACE}};\nuse App\\Http\\Controllers\\Controller;\nuse {{REQUEST_NAMESPACE}};\nuse {{RESOURCE_COLLECTION_NAMESPACE}};\n\nclass {{CONTROLLER_NAME}} extends Controller\n{\n    /**\n     * Display a listing of the resource.\n     */\n    public function index()\n    {\n        $this->authorize('viewAny', {{MODEL_CLASS}}::class);\n\n        {{INDEX_METHOD}}\n    }\n\n    /**\n     * Store a newly created resource in storage.\n     */\n    public function store({{REQUEST_CLASS}} $request)\n    {\n        $this->authorize('create', {{MODEL_CLASS}}::class);\n\n        {{STORE_METHOD}}\n    }\n\n    /**\n     * Display the specified resource.\n     */\n    public function show({{MODEL_CLASS}} ${{MODEL_VARIABLE}})\n    {\n        $this->authorize('view', ${{MODEL_VARIABLE}});\n\n        {{SHOW_METHOD}}\n    }\n\n    /**\n     * Update the specified resource in storage.\n     */\n    public function update({{REQUEST_CLASS}} $request, {{MODEL_CLASS}} ${{MODEL_VARIABLE}})\n    {\n        $this->authorize('update', ${{MODEL_VARIABLE}});\n\n        {{UPDATE_METHOD}}\n    }\n\n    /**\n     * Remove the specified resource from storage.\n     */\n    public function destroy({{MODEL_CLASS}} ${{MODEL_VARIABLE}})\n    {\n        $this->authorize('delete', ${{MODEL_VARIABLE}});\n\n        {{DESTROY_METHOD}}\n    }\n}\n"
  },
  {
    "path": "src/stubs/factories/factory.stub",
    "content": "<?php\n\nnamespace Database\\Factories;\n\nuse {{MODEL_NAMESPACE}}\\{{MODEL_NAME}};\nuse Illuminate\\Database\\Eloquent\\Factories\\Factory;\n\n/**\n * @extends \\Illuminate\\Database\\Eloquent\\Factories\\Factory<\\{{MODEL_NAMESPACE}}\\{{MODEL_NAME}}>\n */\nclass {{CLASS_NAME}} extends Factory\n{\n    /**\n     * Define the model's default state.\n     *\n     * @return array<string, mixed>\n     */\n    public function definition(): array\n    {\n        return [\n           'name' => $this->faker->name,\n        ];\n    }\n}\n"
  },
  {
    "path": "src/stubs/migrations/migration.stub",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nreturn new class extends Migration\n{\n    /**\n     * Schema table name to migrate\n     */\n    public $table = '{{TABLE_NAME}}';\n\n    /**\n     * Run the migrations.\n     */\n    public function up(): void\n    {\n        Schema::create($this->table, function (Blueprint $table) {\n            $table->id();\n            $table->string('name');\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     */\n    public function down(): void\n    {\n        Schema::dropIfExists($this->table);\n    }\n};\n"
  },
  {
    "path": "src/stubs/models/model.stub",
    "content": "<?php\n\nnamespace {{NAMESPACE}};\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\n\nclass {{CLASS_NAME}} extends Model\n{\n    use HasFactory;\n\n    /**\n     * The attributes that are mass assignable.\n     *\n     * @var array\n     */\n    protected $fillable = [\n        'name'\n    ];\n\n}\n"
  },
  {
    "path": "src/stubs/policies/api.policies.stub",
    "content": "<?php\n\nnamespace {{NAMESPACE}};\n\nuse {{MODEL_NAMESPACE}}\\{{MODEL_CLASS}};\nuse {{MODEL_NAMESPACE}}\\User;\nuse Illuminate\\Auth\\Access\\HandlesAuthorization;\n\nclass {{CLASS_NAME}}\n{\n    use HandlesAuthorization;\n\n    /**\n     * Determine whether the user can view any {{MODEL_VARIABLE}}.\n     */\n    public function viewAny(User $user): bool\n    {\n        //\n    }\n\n    /**\n     * Determine whether the user can view the {{MODEL_VARIABLE}}.\n     */\n    public function view(User $user, {{MODEL_CLASS}} ${{MODEL_VARIABLE}}): bool\n    {\n        //\n    }\n\n    /**\n     * Determine whether the user can create {{MODEL_VARIABLE}}.\n     */\n    public function create(User $user): bool\n    {\n        //\n    }\n\n    /**\n     * Determine whether the user can update the {{MODEL_VARIABLE}}.\n     */\n    public function update(User $user, {{MODEL_CLASS}} ${{MODEL_VARIABLE}}): bool\n    {\n        //\n    }\n\n    /**\n     * Determine whether the user can delete the {{MODEL_VARIABLE}}.\n     */\n    public function delete(User $user, {{MODEL_CLASS}} ${{MODEL_VARIABLE}}): bool\n    {\n        //\n    }\n\n    /**\n     * Determine whether the user can restore the {{MODEL_VARIABLE}}.\n     */\n    public function restore(User $user, {{MODEL_CLASS}} ${{MODEL_VARIABLE}}): bool\n    {\n        //\n    }\n\n    /**\n     * Determine whether the user can permanently delete the {{MODEL_VARIABLE}}.\n     */\n    public function forceDelete(User $user, {{MODEL_CLASS}} ${{MODEL_VARIABLE}}): bool\n    {\n        //\n    }\n}\n"
  },
  {
    "path": "src/stubs/requests/api.request.stub",
    "content": "<?php\n\nnamespace {{NAMESPACE}};\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\n\nclass {{CLASS_NAME}} extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     */\n    public function authorize(): bool\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @return array<string, \\Illuminate\\Contracts\\Validation\\ValidationRule|array|string>\n     */\n    public function rules(): array\n    {\n        return [\n            'name' => ['required'],\n        ];\n    }\n}\n"
  },
  {
    "path": "src/stubs/resources/api.collection.stub",
    "content": "<?php\n\nnamespace {{NAMESPACE}};\n\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Http\\Resources\\Json\\ResourceCollection;\n\nclass {{CLASS_NAME}} extends ResourceCollection\n{\n    /**\n     * The resource that this resource collects.\n     *\n     * @var string\n     */\n    public $collects = '{{RESOURCE_NAMESPACE}}\\{{RESOURCE_CLASS_NAME}}';\n\n    /**\n     * Transform the resource collection into an array.\n     *\n     * @return array<int|string, mixed>\n     */\n    public function toArray(Request $request): array\n    {\n        return parent::toArray($request);\n    }\n}\n"
  },
  {
    "path": "src/stubs/resources/api.resource.stub",
    "content": "<?php\n\nnamespace {{NAMESPACE}};\n\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass {{CLASS_NAME}} extends JsonResource\n{\n    /**\n     * Transform the resource into an array.\n     *\n     * @return array<string, mixed>\n     */\n    public function toArray(Request $request): array\n    {\n        return parent::toArray($request);\n    }\n}\n"
  },
  {
    "path": "src/stubs/routes/api.routes.stub",
    "content": "/*\n|--------------------------------------------------------------------------\n| {{MODEL_NAME}} endpoints\n|--------------------------------------------------------------------------\n */\nRoute::name('{{ROUTE_NAME}}.')->controller({{CONTROLLER_NAME}}::class)->prefix('{{ROUTE_NAME}}')->group(function () {\n    Route::get('/', 'index')->name('index');\n    Route::post('/', 'store')->name('create');\n    Route::get('/{{{MODEL_VARIABLE}}}', 'show')->name('show');\n    Route::patch('/{{{MODEL_VARIABLE}}}', 'update')->name('update');\n    Route::delete('/{{{MODEL_VARIABLE}}}', 'destroy')->name('destroy');\n});\n"
  },
  {
    "path": "src/stubs/seeds/seed.stub",
    "content": "<?php\n\nnamespace Database\\Seeders;\n\nuse {{MODEL_NAMESPACE}}\\{{MODEL_NAME}};\nuse Illuminate\\Database\\Seeder;\n\nclass {{CLASS_NAME}} extends Seeder\n{\n    private $numberOf{{MODEL_PLURAL}} = 10;\n\n    /**\n     * Run the database seeds.\n     */\n    public function run(): void\n    {\n        $this->command->table(['{{MODEL_PLURAL}} table seeder notice'], [\n            ['Edit this file to change the number of {{MODEL_PLURAL}} created'],\n        ]);\n\n        $this->command->info('Creating ' . $this->numberOf{{MODEL_PLURAL}} . ' {{MODEL_PLURAL}} ...');\n        $bar = $this->command->getOutput()->createProgressBar($this->numberOf{{MODEL_PLURAL}});\n\n        for ($i = 0; $i < $this->numberOf{{MODEL_PLURAL}}; ++$i) {\n            {{MODEL_NAME}}::factory()->create();\n            $bar->advance();\n        }\n\n        $bar->finish();\n        $this->command->info('');\n    }\n}\n"
  },
  {
    "path": "tests/CollectionGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\CollectionGenerator;\n\nclass CollectionGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_filename()\n    {\n        $generator = new CollectionGenerator($this->model);\n        $filename = $generator->fileName();\n        $generator->handle();\n\n        $this->assertEquals($filename, \"{$generator->className()}.php\");\n    }\n\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new CollectionGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, create_class_name($this->model, CollectionGenerator::class));\n    }\n\n    /** @test */\n    public function it_creates_the_collection_file()\n    {\n        $generator = new CollectionGenerator($this->model);\n        $config = namespace_path(config('laravel-resources.collections.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_collection_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.collections.namespace', 'App\\Http\\Resources');\n        $generator = new CollectionGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.collections.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_defined_in_the_configuration_file_for_the_collection()\n    {\n        config()->set('laravel-resources.collections.suffix', $suffix = 'Suffix');\n        config()->set('laravel-resources.collections.prefix', null);\n\n        $generator = new CollectionGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$this->model}Collection{$suffix}\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_prefix_defined_in_the_configuration_file_for_the_collection()\n    {\n        config()->set('laravel-resources.collections.suffix', null);\n        config()->set('laravel-resources.collections.prefix', $prefix = 'PrefixAPI');\n\n        $generator = new CollectionGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Collection\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_and_prefix_defined_in_the_configuration_file_for_the_collection()\n    {\n        config()->set('laravel-resources.collections.prefix', $prefix = 'Foo');\n        config()->set('laravel-resources.collections.suffix', $suffix = 'BarAPI');\n\n        $generator = new CollectionGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Collection{$suffix}\", $generator->className());\n    }\n}\n"
  },
  {
    "path": "tests/ControllerGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\ControllerGenerator;\n\nclass ControllerGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_filename()\n    {\n        $generator = new ControllerGenerator($this->model);\n        $filename = $generator->fileName();\n        $generator->handle();\n\n        $this->assertEquals($filename, \"{$generator->className()}.php\");\n    }\n\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new ControllerGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, create_class_name($this->model, ControllerGenerator::class));\n    }\n\n    /** @test */\n    public function it_creates_the_controller_file()\n    {\n        $generator = new ControllerGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.controllers.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_controller_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.controllers.namespace', 'App\\Http\\Controllers\\API');\n\n        $generator = new ControllerGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.controllers.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_defined_in_the_configuration_file_for_the_controller()\n    {\n        config()->set('laravel-resources.controllers.suffix', $suffix = 'Suffix');\n        config()->set('laravel-resources.controllers.prefix', null);\n\n        $generator = new ControllerGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$this->model}Controller{$suffix}\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_prefix_defined_in_the_configuration_file_for_the_controller()\n    {\n        config()->set('laravel-resources.controllers.prefix', $prefix = 'Prefix');\n        config()->set('laravel-resources.controllers.suffix', null);\n\n        $generator = new ControllerGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Controller\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_and_prefix_defined_in_the_configuration_file_for_the_controller()\n    {\n        config()->set('laravel-resources.controllers.prefix', $prefix = 'Foo');\n        config()->set('laravel-resources.controllers.suffix', $suffix = 'BarAPI');\n\n        $generator = new ControllerGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Controller{$suffix}\", $generator->className());\n    }\n}\n"
  },
  {
    "path": "tests/FactoryGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\FactoryGenerator;\n\nclass FactoryGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new FactoryGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, 'UserFactory');\n    }\n\n    /** @test */\n    public function it_creates_the_migration_file()\n    {\n        $generator = new FactoryGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.factories').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_migration_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.database.factories', 'database/dummy');\n\n        $generator = new FactoryGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.factories').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_migration_in_the_default_namespace()\n    {\n        $generator = new FactoryGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.factories').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n}\n"
  },
  {
    "path": "tests/MigrationGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\MigrationGenerator;\n\nclass MigrationGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new MigrationGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, 'CreateUsersTable');\n    }\n\n    /** @test */\n    public function it_creates_the_migration_file()\n    {\n        $generator = new MigrationGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.migrations').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_migration_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.database.migrations', 'database/dummy');\n\n        $generator = new MigrationGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.migrations').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_migration_in_the_default_namespace()\n    {\n        $generator = new MigrationGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.migrations').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n}\n"
  },
  {
    "path": "tests/ModelGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\ModelGenerator;\n\nclass ModelGeneratorTest extends TestCase\n{\n    /**\n     * Override to the model for this test suite.\n     *\n     * @var string\n     */\n    protected $model = 'Post';\n\n    /** @test */\n    public function it_creates_the_model_file()\n    {\n        $generator = new ModelGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.models.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_model_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.models.namespace', 'App\\Models');\n\n        $generator = new ModelGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.models.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n}\n"
  },
  {
    "path": "tests/PolicyGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\PolicyGenerator;\n\nclass PolicyGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_filename()\n    {\n        $generator = new PolicyGenerator($this->model);\n        $filename = $generator->fileName();\n        $generator->handle();\n\n        $this->assertEquals($filename, \"{$generator->className()}.php\");\n    }\n\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new PolicyGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, create_class_name($this->model, PolicyGenerator::class));\n    }\n\n    /** @test */\n    public function it_creates_the_policy_file()\n    {\n        $generator = new PolicyGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.policies.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_policy_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.policies.namespace', 'App\\Http\\Policies');\n\n        $generator = new PolicyGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.policies.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_defined_in_the_configuration_file_for_the_policy()\n    {\n        config()->set('laravel-resources.policies.suffix', $suffix = 'Suffix');\n        config()->set('laravel-resources.policies.prefix', null);\n\n        $generator = new PolicyGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$this->model}Policy{$suffix}\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_prefix_defined_in_the_configuration_file_for_the_policy()\n    {\n        config()->set('laravel-resources.policies.prefix', $prefix = 'Prefix');\n        config()->set('laravel-resources.policies.suffix', null);\n\n        $generator = new PolicyGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Policy\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_and_prefix_defined_in_the_configuration_file_for_the_policy()\n    {\n        config()->set('laravel-resources.policies.prefix', $prefix = 'Foo');\n        config()->set('laravel-resources.policies.suffix', $suffix = 'BarAPI');\n\n        $generator = new PolicyGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Policy{$suffix}\", $generator->className());\n    }\n}\n"
  },
  {
    "path": "tests/RequestGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\RequestGenerator;\n\nclass RequestGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_filename()\n    {\n        $generator = new RequestGenerator($this->model);\n        $filename = $generator->fileName();\n        $generator->handle();\n\n        $this->assertEquals($filename, \"{$generator->className()}.php\");\n    }\n\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new RequestGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, create_class_name($this->model, RequestGenerator::class));\n    }\n\n    /** @test */\n    public function it_creates_the_request_file()\n    {\n        $generator = new RequestGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.requests.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_request_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.requests.namespace', 'App\\Http');\n\n        $generator = new RequestGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.requests.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_defined_in_the_configuration_file_for_the_request()\n    {\n        config()->set('laravel-resources.requests.suffix', $suffix = 'Suffix');\n        config()->set('laravel-resources.requests.prefix', null);\n\n        $generator = new RequestGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$this->model}Request{$suffix}\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_prefix_defined_in_the_configuration_file_for_the_request()\n    {\n        config()->set('laravel-resources.requests.prefix', $prefix = 'PrefixAPI');\n        config()->set('laravel-resources.requests.suffix', null);\n\n        $generator = new RequestGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Request\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_and_prefix_defined_in_the_configuration_file_for_the_request()\n    {\n        config()->set('laravel-resources.requests.prefix', $prefix = 'Foo');\n        config()->set('laravel-resources.requests.suffix', $suffix = 'BarAPI');\n\n        $generator = new RequestGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Request{$suffix}\", $generator->className());\n    }\n}\n"
  },
  {
    "path": "tests/ResourceCommandTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse Illuminate\\Support\\Facades\\File;\n\nclass ResourceCommandTest extends TestCase\n{\n    /** @test */\n    public function it_should_not_create_the_model_if_it_does_not_exists_and_the_user_deny_the_question()\n    {\n        $this->artisan('resources:create', ['model' => 'Foo'])\n            ->expectsOutput('The model Foo does not exists.')\n            ->expectsQuestion('Should I create it?', false);\n\n        $this->assertFalse(File::exists(app_path('/Foo.php')));\n    }\n\n    /** @test */\n    public function it_creates_the_model_if_it_does_not_exists_and_the_user_accepts_the_question()\n    {\n        $this->defaultQuestions();\n\n        $path = namespace_path(config('laravel-resources.models.namespace').'\\\\Foo.php');\n\n        $this->assertTrue(File::exists($path));\n    }\n\n    /** @test */\n    public function it_creates_the_migration_when_the_response_to_the_question_is_true()\n    {\n        $this->defaultQuestions(['migration']);\n\n        $this->assertEquals(1, collect(File::files(database_path('/migrations')))->count());\n    }\n\n    /** @test */\n    public function it_creates_the_factory_when_the_response_to_the_question_is_true()\n    {\n        $this->defaultQuestions(['factory']);\n\n        $this->assertEquals(1, collect(File::files(database_path('/factories')))->count());\n    }\n\n    /** @test */\n    public function it_creates_the_seeder_when_the_response_to_the_question_is_true()\n    {\n        $this->defaultQuestions(['migration', 'factory', 'seeder']);\n\n        $this->assertEquals(1, collect(File::files(database_path('/migrations')))->count());\n        $this->assertEquals(1, collect(File::files(database_path('/seeders')))->count());\n        $this->assertEquals(1, collect(File::files(database_path('/factories')))->count());\n    }\n\n    /** @test */\n    public function it_creates_the_all_files_when_the_response_to_the_question_is_always_true()\n    {\n        $this->defaultQuestions(['seeder']);\n\n        $this->assertEquals(1, collect(File::files(database_path('/seeders')))->count());\n    }\n\n    /**\n     * Create the command boilerplate for the model creation.\n     *\n     * @return void\n     */\n    protected function defaultQuestions($args = [], $shouldCreate = true)\n    {\n        $this->artisan('resources:create', ['model' => 'Foo'])\n            ->expectsOutput('The model Foo does not exists.')\n            ->expectsQuestion('Should I create it?', $shouldCreate)\n            ->expectsQuestion('Should I create the migration for Foo?', in_array('migration', $args))\n            ->expectsQuestion('Should I create the factory for Foo?', in_array('factory', $args))\n            ->expectsQuestion('Should I create the seeder for Foo?', in_array('seeder', $args));\n    }\n}\n"
  },
  {
    "path": "tests/ResourceGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\ResourceGenerator;\n\nclass ResourceGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_filename()\n    {\n        $generator = new ResourceGenerator($this->model);\n        $filename = $generator->fileName();\n        $generator->handle();\n\n        $this->assertEquals($filename, \"{$generator->className()}.php\");\n    }\n\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new ResourceGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, create_class_name($this->model, ResourceGenerator::class));\n    }\n\n    /** @test */\n    public function it_creates_the_resource_file()\n    {\n        $generator = new ResourceGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.resources.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_request_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.resources.namespace', 'App\\Http');\n\n        $generator = new ResourceGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.resources.namespace').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_defined_in_the_configuration_file_for_the_resource()\n    {\n        config()->set('laravel-resources.resources.suffix', $suffix = 'Suffix');\n        config()->set('laravel-resources.resources.prefix', null);\n\n        $generator = new ResourceGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$this->model}Resource{$suffix}\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_prefix_defined_in_the_configuration_file_for_the_resource()\n    {\n        config()->set('laravel-resources.resources.prefix', $prefix = 'Prefix');\n        config()->set('laravel-resources.resources.suffix', null);\n\n        $generator = new ResourceGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Resource\", $generator->className());\n    }\n\n    /** @test */\n    public function it_generates_the_name_with_the_suffix_and_prefix_defined_in_the_configuration_file_for_the_resource()\n    {\n        config()->set('laravel-resources.resources.prefix', $prefix = 'Foo');\n        config()->set('laravel-resources.resources.suffix', $suffix = 'BarAPI');\n\n        $generator = new ResourceGenerator($this->model);\n        $generator->handle();\n\n        $this->assertEquals(\"{$prefix}{$this->model}Resource{$suffix}\", $generator->className());\n    }\n}\n"
  },
  {
    "path": "tests/SeederGeneratorTest.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse tiagomichaelsousa\\LaravelResources\\Generators\\SeederGenerator;\n\nclass SeederGeneratorTest extends TestCase\n{\n    /** @test */\n    public function it_generates_the_right_class_name()\n    {\n        $generator = new SeederGenerator($this->model);\n        $filename = $generator->className();\n        $generator->handle();\n\n        $this->assertEquals($filename, 'UsersTableSeeder');\n    }\n\n    /** @test */\n    public function it_creates_the_seeder_file()\n    {\n        $generator = new SeederGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.seeds').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_seeder_in_the_config_namespace()\n    {\n        config()->set('laravel-resources.database.seeds', 'database/dummy');\n\n        $generator = new SeederGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.seeds').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n\n    /** @test */\n    public function it_creates_the_seeder_in_the_default_namespace()\n    {\n        $generator = new SeederGenerator($this->model);\n\n        $config = namespace_path(config('laravel-resources.database.seeds').\"\\\\{$generator->fileName()}\");\n\n        $generator->handle();\n\n        $this->assertFileExists($config);\n    }\n}\n"
  },
  {
    "path": "tests/TestCase.php",
    "content": "<?php\n\nnamespace tiagomichaelsousa\\LaravelResources\\Tests;\n\nuse Illuminate\\Support\\Facades\\File;\nuse Orchestra\\Testbench\\TestCase as Orchestra;\nuse tiagomichaelsousa\\LaravelResources\\LaravelResourcesServiceProvider;\n\nabstract class TestCase extends Orchestra\n{\n    /**\n     * Default model to run the test suite.\n     *\n     * @var string\n     */\n    protected $model = 'User';\n\n    /**\n     * Setup the test environment.\n     *\n     * @return void\n     */\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->clearDirectories();\n\n        $this->initialize();\n    }\n\n    /**\n     * Clean up the testing environment before the next test.\n     *\n     * @return void\n     */\n    protected function tearDown(): void\n    {\n        parent::tearDown();\n    }\n\n    /**\n     * Clean up the testing environment directories before the next test.\n     *\n     * @return void\n     */\n    private function clearDirectories()\n    {\n        File::cleanDirectory(base_path('app'));\n        File::deleteDirectory(base_path('routes'));\n        File::cleanDirectory(database_path('migrations'));\n        File::cleanDirectory(database_path('factories'));\n        File::cleanDirectory(database_path('seeders'));\n        File::cleanDirectory(database_path('dummy'));\n    }\n\n    /**\n     * Create the test suite default folder structure.\n     *\n     * @return void\n     */\n    private function initialize()\n    {\n        if (! File::exists(namespace_path(config('laravel-resources.models.namespace')).'/User.php')) {\n            $this->artisan('make:model User');\n        }\n\n        if (! File::exists($route = namespace_path(config('laravel-resources.routes.path')).'/'.config('laravel-resources.routes.filename'))) {\n            make_directory(namespace_path(config('laravel-resources.routes.path')));\n            file_put_contents($route, '<?php');\n        }\n    }\n\n    /**\n     * Create the test suite default folder structure.\n     *\n     * @return void\n     */\n    protected function getPackageProviders($app)\n    {\n        return [\n            LaravelResourcesServiceProvider::class,\n        ];\n    }\n}\n"
  }
]