Announcing the release of Lumen 5.2
Lumen is a micro framework carved out of Laravel.
Slim, Flight, Silex are all examples of micro frameworks that you can easily employ to build your strictly API applications without using almighty Laravel or CakePHP or Symfony or even Zend.
There are so many components you wouldn’t need in the full-fledged frameworks when building APIs and several micro-services, thus the need for micro-frameworks like Lumen.
Lumen 5.2.0 was released about 2 hours ago and it’s design has shifted towards focusing on stateless APIs. Two major components were removed to achieve this:
1. Sessions
2. Views
If you need them, you’ll have to upgrade to Laravel 5.2
Changes Introduced in Lumen 5.2.0
1. Authentication.
Since sessions have been removed, authentication is now based on stateless authentication via headers and API tokens.
You now have complete control over the AuthServiceProvider
To use Lumen’s authentication features, uncomment the call to register AuthServiceProvider in bootstrap/app.php
around line 82 like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* |-------------------------------------------------------------------------- | Register Service Providers |-------------------------------------------------------------------------- | | Here we will register all of the application's service providers which | are used to bind services into the container. Service providers are | totally optional, so you are not required to uncomment this line. | */ // $app->register(AppProvidersAppServiceProvider::class); // $app->register(AppProvidersAuthServiceProvider::class); // $app->register(AppProvidersEventServiceProvider::class); |
In AuthServiceProvider.php, we have this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * Boot the authentication services for the application. * * @return void */ public function boot() { // Here you may define how you wish users to be authenticated for your Lumen // application. The callback which receives the incoming request instance // should return either a User instance or null. You're free to obtain // the User instance via an API token or any other method necessary. Auth::viaRequest('api', function ($request) { if ($request->input('api_token')) { return User::where('api_token', $request->input('api_token'))->first(); } }); } |
The viaRequest
method accepts a callback function  which accepts the incoming request and returns the user instance. By default it assumes api_token
, as a developer, you can state whatever parameter you want to actually enforce.
You can access the authenticated user still using Auth::user()
like we have in the Laravel Framework but you need to uncomment $app->withFacades()
in the bootstrap/app.php file:
1 2 3 4 5 6 7 |
$app = new LaravelLumenApplication( realpath(__DIR__.'/../') ); // $app->withFacades(); // $app->withEloquent(); |
One more thing,
For your routes that need authentication, you need to uncomment
$app->routeMiddleware
in bootstrap/app.php
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* |-------------------------------------------------------------------------- | Register Middleware |-------------------------------------------------------------------------- | | Next, we will register the middleware with the application. These can | be global middleware that run before and after each request into a | route or middleware that'll be assigned to some specific routes. | */ // $app->middleware([ // AppHttpMiddlewareExampleMiddleware::class // ]); // $app->routeMiddleware([ // 'auth' => AppHttpMiddlewareAuthenticate::class, // ]); |
and then use auth
as a middleware on those routes the same way you set middlewares in Laravel 5.2
2. Testing Helpers
There are several testing helper functions in Lumen, since sessions have been removed, all of the form interaction testing helpers have been removed.
3. IronMQ removed
The IronMQ queue driver has been moved into its own package and is no longer shipped with the core framework. Â http://github.com/LaravelCollective/iron-queue
Conclusion
The upgrade guide from Lumen 5.1 to Lumen 5.2 is here. Check it out.
Please, let me know if you have any questions or observations in the comments section.

- How to build your own Youtube – Part 10 - August 1, 2016
- How to build your own Youtube – Part 9 - July 25, 2016
- How to build your own Youtube – Part 8 - July 23, 2016
- How to build your own Youtube – Part 6 - July 6, 2016
- Introducing Laravel Password v1.0 - July 3, 2016
- How to build your own Youtube – Part 5 - June 28, 2016
- How to build your own Youtube – Part 4 - June 23, 2016
- How to build your own Youtube – Part 3 - June 15, 2016
- How to build your own Youtube – Part 2 - June 8, 2016
- How to build your own Youtube – Part 1 - June 1, 2016