Exciting things

Lumen 5.2 and things you should be noticed


I am starting developing the RESTful API application for my LaunchCMS. LaunchCMS is an open source headlesss CMS platform – focuses on content management and providing APIs for developers to build their awesome ideas. I will share detail about LaunchCMS in later posts. In this article, I just want to focus on some lessons I have learned when setting up the RESTful API application today.

I decide to pick Lumen 5.2 as the main technology for building the RESTful API application. It’s really fast and already trimmed unnecessary parts of Laravel to make the performance optimised very well.

However, the first day makes me so headache with many things coming from Lumen and the differences between the philosophy of Lumen vs Laravel.

Missing config_path function

Many packages use the config_path for resolving the configuration file. Lumen is missing this method in their code. You can follow this gist to solve this problem. However, in my case – I just put the below code after the ENV setup  in app.php as below:

if ( ! function_exists('config_path'))
    function config_path($path = '')
        return app()->basePath() . '/config' . ($path ? '/' . $path : $path);

Specific problem with jenssegers/laravel-mongodb package

Another problem comes with laravel-mongodb package, the way of configuration loading of laralve-mongodb doesn’t work with Lumen if you load its service provider after the line: $app->withEloquent();

There are some approaches that can help to solve this issue at this: https://github.com/jenssegers/laravel-mongodb/issues/470 For now, I solved it quickly by just changing the ordering of loading between $app->withEloquent() and the line to register jessenger service provider as below:


Lumen hates Facade

Taylor Rotwell has posted an article to reply about using or stop using Facade in Laravel http://taylorotwell.com/response-dont-use-facades/ for a long time ago. However, I am not convinced with the reason of using Facade as it easily makes the developer violate the Single responsibility rule in the SOLID principles.

In Lumen, even you uncomment the line:


inside app.php to enable Facade works. However, if you look at the method: withFacades – you will see it only supports for builtin aliases of Laravel. If you create Facade inside your package and use directly your Facade in Controller of Lumen, it never works. Instead of that, you need to use IoC or get the service from $app. You can refer to this article (http://andyfleming.com/using-lumen-without-facades/) for detail on the solution.

Some packages will not work because Lumen removed the VERSION constant in Application class

I am also using Dingo package for the API app. In this package (and I believe many others,eg: Cviebrock\LaravelElasticsearch), they have the need to compare the version of the framework to add some different logics.

However, the application class (Laravel\Lumen\Application) suddenly removed the VERSION constant in the version 5.2 (ref for the issue of Dingo in this case – link).

To fix this issue, I created a custom Application class extend from Laravel\Lumen\Application and add back the constant VERSION = ‘5.2’. Then, in the app.php of Lumen – just replace where they create the application instance as below:

$app = new App\ApiApplication(

App\ApiApplication is my custom Application class.

Event Service provider not found

I have a core package which is used both for the LaunchCMS (Admin site is built on Laravel) and API (built on Lumen). In this package, I put my own LaunchCMSEventServiceProvider class to take care all necessary event listening, broadcasting.

This LaunchCMSEventServiceProvider extends from Illuminate\Foundation\Support\Providers\EventServiceProvider. However, Lumen implemented another class: Laravel\Lumen\Providers\EventServiceProvider. These EventServiceProvider classes  conflicts each other in term of naming. Check this out for detail: https://github.com/andersao/l5-repository/issues/117

To fix this, you can apply the patch on above link.

Solving these issues takes me hours to figure out the root cause and what’s happened. So, I hope that it can help to save you a bit of time if you read through this article.



Tagged on: , ,

One thought on “Lumen 5.2 and things you should be noticed

  1. Pingback: Lumen 5.2 and things you should be noticed – Exciting things – fullstack.blog

Leave a Reply

Your email address will not be published. Required fields are marked *