phplaravellaravel-10laravel-moduleslaravel-config

Laravel Modules dynamic activation by config


I just recently started working with Laravel 10. I'm using nwidart/laravel-modules v10 for creating modules in my new project.

Since the project is going to be an SaaS product, I am also using stancl/tenancy for multiple tenants. I have a config file for every tenant and want to dynamically activate or deactivate the modules from the tenants config.

The Config-Key is ActivatedModules and looks like this:

'ActivatedModules' => [
    ['id' => 'homepage', 'name' => 'Homepage', 'icon' => 'homepage', 'visibility' => 'extern', 'no' => 1], // Homepage
],

My idea was to uses the method Module::all() of use Nwidart\Modules\Facades\Module; as mentioned in the docs.

My Problem is that there is an error saying that this funcion is not existing and on the website comes the following error:
Fatal error: Uncaught RuntimeException: A facade root has not been set. in
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:350
Stack trace: #0
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\RegisterErrorViewPaths.php(16):
Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...',
Array) #1
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php(674):
Illuminate\Foundation\Exceptions\RegisterErrorViewPaths->__invoke() #2
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php(655):
Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths() #3
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php(586):
Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException))
#4 D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php(492):
Illuminate\Foundation\Exceptions\Handler->prepareResponse(Object(Illuminate\Http\Request),
Object(Symfony\Component\HttpKernel\Exception\HttpException)) #5
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\Handler.php(409):
Illuminate\Foundation\Exceptions\Handler->renderExceptionResponse(Object(Illuminate\Http\Request),
Object(RuntimeException)) #6
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(509):
Illuminate\Foundation\Exceptions\Handler->render(Object(Illuminate\Http\Request),
Object(RuntimeException)) #7
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(148):
Illuminate\Foundation\Http\Kernel->renderException(Object(Illuminate\Http\Request),
Object(RuntimeException)) #8
D:\Programmieren\referee365\public\index.php(51):
Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#9 D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Foundation\resources\server.php(16):
require_once('D:\\Programmiere...') #10 {main} thrown in
D:\Programmieren\referee365\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php
on line 350

I hope some of you can help me with this, in the best case, easy problem.


Solution

  • So I found my mistake.

    If anyone is interested in the solution..

    I used the Module:all() inside the config/app.php where the Facade Roots aren't set yet. I'm now using it outside of this file and it works just fine.