Laravel-modules: Working with Lumen and Laravel Modules, but I have no success. Details are inside.

Created on 26 Jul 2018  路  2Comments  路  Source: nWidart/laravel-modules

Hi there,

I am currently working with Lumen and I want to add Laravel Modules. I am looking at the tutorial here: https://nwidart.com/laravel-modules/v3/lumen and I think I followed the tutorial fine.

Up until the Lumen and the Laravel Modules is set there is no error. The errors come in after I generate new module with: php artisan module:make HelloWorld. There are four errors so far and I am, kinda, convinced that Lumen and Laravel Modules do not work together, at least they do not work together out-of-the-box.

The first error:

first-error

For the first error I should edit ServiceProvider.php (for this case it is HelloWorldServiceProvider.php):

  • I need to add use Illuminate\Support\Facades\Config;.
  • I need to change \Config into Config since it is already imported in the uppermost of this PHP file.

The second error:

second-error

The second error is because the default configuration of Lumen. I need to activate that the Lumen web application is using Laravel's Facade. I need to open bootstrap/app.php and then uncomment this line:

// $app->withFacades();

The third error:

third-error

The error can be fixed with changing HelloWorldServiceProvider.php:

...
        }, Config::get('view.paths')), [$sourcePath]), 'helloworld');
...

With:

...
        }, [Config::get('view.paths'))], [$sourcePath]), 'helloworld');
...

The fourth error:

fourth-error

Stopped right here at this error.

So how can I get Lumen working with Laravel Modules?

Most helpful comment

@notalentgeek Hi, the only thing I can think of right now as a quick fix as I am having the same thing, and this is a issue to @nWidart laravel-modules poor lumen support, probably at start.php --> app()->routesAreCached()

First/Second error:

You can basically do it like this too:

$app->withFacades(true, [
    'Illuminate\Support\Facades\Config' => 'Config',
]);

Third error:

create a directory config and copy over the view.php configuration file from laravel, file content is something like:

return [

    'paths' => [
        resource_path('views'),
    ],

    'compiled' => realpath(storage_path('framework/views')),

];

and load the configuration file using:

$app->configure('view');

Fourth error:

Sadly the container does not extends macro so I was forced to do this:

// bootstrap/app.php

class LumenApp extends Laravel\Lumen\Application
{
    public function routesAreCached()
    {
        return false;
    }
}

$app = new LumenApp(realpath(__DIR__ . '/../'));

I am stepping away to lumen and do something else, but I hope this helps.

~~

All 2 comments

@notalentgeek Hi, the only thing I can think of right now as a quick fix as I am having the same thing, and this is a issue to @nWidart laravel-modules poor lumen support, probably at start.php --> app()->routesAreCached()

First/Second error:

You can basically do it like this too:

$app->withFacades(true, [
    'Illuminate\Support\Facades\Config' => 'Config',
]);

Third error:

create a directory config and copy over the view.php configuration file from laravel, file content is something like:

return [

    'paths' => [
        resource_path('views'),
    ],

    'compiled' => realpath(storage_path('framework/views')),

];

and load the configuration file using:

$app->configure('view');

Fourth error:

Sadly the container does not extends macro so I was forced to do this:

// bootstrap/app.php

class LumenApp extends Laravel\Lumen\Application
{
    public function routesAreCached()
    {
        return false;
    }
}

$app = new LumenApp(realpath(__DIR__ . '/../'));

I am stepping away to lumen and do something else, but I hope this helps.

~~

I'll close this for now as lumen will probably be dropped as no-one is able to fix the issue with it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ojasseh picture ojasseh  路  3Comments

dang-tien picture dang-tien  路  3Comments

morningmemo picture morningmemo  路  3Comments

alexandretaz picture alexandretaz  路  3Comments

quentingosset picture quentingosset  路  4Comments