dotswan / modules-auto-discover
Discover configs, translations, views, and .. automatically
Requires
- php: ^8.1
- nwidart/laravel-modules: ^11.0
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
Automatically discover and register configurations, translations, and more from your nWidart/laravel-modules modules.
Table of Contents
Introduction
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.
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.
Installation
You can install the package via Composer:
composer require dotswan/modules-auto-discover
The package uses Laravel's auto-discovery feature, so no additional steps are required to register the service provider.
Usage
Once installed, the package will automatically discover and register the following resources in your enabled modules:
- Configurations (
Config/
directory) - Translations (
Lang/
directory) - Views (
Resources/views/
directory) - Routes (
Routes/
directory) - Migrations (
Database/Migrations/
directory) - Factories (
Database/Factories/
directory) - Seeds (
Database/Seeders/
directory)
Auto-Discovery
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.
For example, placing a configuration file at Modules/YourModule/Config/permission.php
will make its contents available via Laravel's config()
helper:
// Accessing a configuration value from your module $value = config('permission.key');`
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)
Disabling Auto-Discovery per Module
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:
{ "name": "YourModule", "alias": "yourmodule", ... "auto-discovery": false, ... }
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.
To-Do
- Discover
Config
- Discover
Translations
- Discover
Views
- Discover
Routes
- Discover
Commands
Contributing
Contributions are welcome and encouraged! Please follow these steps to contribute:
-
Fork the repository on GitHub.
-
Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
-
Make your changes.
-
Run
composer lint
to format your code with Pint rules. -
Run
composer test
to run tests orcomposer test-coverage
to generate a coverage report. -
Commit your changes with clear messages.
-
Push your branch to your forked repository:
git push origin feature/your-feature-name
-
Open a pull request on the main repository.
Please make sure to write tests for your changes and ensure all existing tests pass.
License
The MIT License (MIT). Please see License File for more information.
Support
If you encounter any issues or have questions, please contact us via tech@dotswan.com or open an issue on the GitHub repository.