|
| 1 | +# Modules Auto-Discover |
| 2 | + |
| 3 | +Automatically discover and register configurations, translations, and more from your [nWidart/laravel-modules](https://github.com/nWidart/laravel-modules) modules. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +* [Introduction](#introduction) |
| 8 | +* [Installation](#installation) |
| 9 | +* [Usage](#usage) |
| 10 | + * [Auto-Discovery](#auto-discovery) |
| 11 | + * [Disabling Auto-Discovery per Module](#disabling-auto-discovery-per-module) |
| 12 | +* [Contributing](#contributing) |
| 13 | +* [License](#license) |
| 14 | +* [Support](#support) |
| 15 | + |
| 16 | +## Introduction |
| 17 | + |
| 18 | +When using the `nWidart/laravel-modules` package for modular Laravel applications, you might have noticed that configurations, translations, and other resources within your modules are not automatically discovered and registered by Laravel and you need to register/discover them in the `ModuleServiceProvider` for every module. This package bridges that gap by automatically discovering and registering these resources, simplifying your module development process. |
| 19 | + |
| 20 | +With **Modules Auto-Discover**, you no longer need to manually call methods like `registerConfigs()` or `registerTranslationss()` in your module service providers. The package handles the discovery and registration automatically during the application's boot process. |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +You can install the package via Composer: |
| 25 | + |
| 26 | +```bash |
| 27 | +composer require dotswan/modules-auto-discover |
| 28 | +``` |
| 29 | + |
| 30 | +The package uses Laravel's auto-discovery feature, so no additional steps are required to register the service provider. |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +Once installed, the package will automatically discover and register the following resources in your enabled modules: |
| 35 | + |
| 36 | +* **Configurations** (`Config/` directory) |
| 37 | +* **Translations** (`Lang/` directory) |
| 38 | +* **Views** (`Resources/views/` directory) |
| 39 | +* **Routes** (`Routes/` directory) |
| 40 | +* **Migrations** (`Database/Migrations/` directory) |
| 41 | +* **Factories** (`Database/Factories/` directory) |
| 42 | +* **Seeds** (`Database/Seeders/` directory) |
| 43 | + |
| 44 | +### Auto-Discovery |
| 45 | + |
| 46 | +By default, auto-discovery is enabled for all your modules. This means that any resources placed in the standard directories will be automatically registered without any additional configuration. |
| 47 | + |
| 48 | +For example, placing a configuration file at `Modules/YourModule/Config/permission.php` will make its contents available via Laravel's `config()` helper: |
| 49 | + |
| 50 | +```php |
| 51 | +// Accessing a configuration value from your module |
| 52 | +$value = config('permission.key');` |
| 53 | +``` |
| 54 | +**Note:** `nWidart Modules` will create a `config.php` file for every module by default (if you enabled to generate), we recommend you to create a separate file for each configuration to avoid conflicts (don't use `config.php` for all modules) |
| 55 | + |
| 56 | + |
| 57 | +### Disabling Auto-Discovery per Module |
| 58 | + |
| 59 | +If you want to disable auto-discovery for a specific module, you can do so by adding an `"auto-discovery": false` entry to your module's `module.json` file: |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "name": "YourModule", |
| 64 | + "alias": "yourmodule", |
| 65 | + ... |
| 66 | + "auto-discovery": false, |
| 67 | + ... |
| 68 | +} |
| 69 | +``` |
| 70 | +With `auto-discovery` set to `false`, the package will skip the automatic registration of resources for that module. You can then manually register resources in your module's service provider if needed. |
| 71 | + |
| 72 | +## To-Do |
| 73 | +- [x] Discover `Config` |
| 74 | +- [x] Discover `Translations` |
| 75 | +- [ ] Discover `Views` |
| 76 | +- [ ] Discover `Routes` |
| 77 | +- [ ] Discover `Commands` |
| 78 | + |
| 79 | +## Contributing |
| 80 | + |
| 81 | +Contributions are welcome and encouraged! Please follow these steps to contribute: |
| 82 | + |
| 83 | +1. Fork the repository on GitHub. |
| 84 | +2. Create a new branch for your feature or bug fix: |
| 85 | + |
| 86 | + ```bash |
| 87 | + git checkout -b feature/your-feature-name |
| 88 | + ``` |
| 89 | + |
| 90 | +3. Make your changes. |
| 91 | +4. Run `composer lint` to format your code with Pint rules. |
| 92 | +5. Run `composer test` to run tests or `composer test-coverage` to generate a coverage report. |
| 93 | +6. Commit your changes with clear messages. |
| 94 | +7. Push your branch to your forked repository: |
| 95 | + |
| 96 | + ```bash |
| 97 | + git push origin feature/your-feature-name |
| 98 | + ``` |
| 99 | + |
| 100 | +8. Open a pull request on the main repository. |
| 101 | + |
| 102 | +Please make sure to write tests for your changes and ensure all existing tests pass. |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 107 | + |
| 108 | +## Support |
| 109 | + |
| 110 | +If you encounter any issues or have questions, please contact us via [tech@dotswan.com](mailto:tech@dotswan.com) or open an issue on the [GitHub repository](https://github.com/dotswan/modules-auto-discover/issues). |
0 commit comments