Where to register Facades & Service Providers in Lumen

To register a facade with an alias, go to bootstrap/app.php and uncomment:

$app->withFacades();

... it instructs the framework to start with facades. To add your facades, just put them in an array and pass the array as a second argument, while setting the first argument to true, as follows:

$app->withFacades(true, [
    'Tymon\JWTAuth\Facades\JWTAuth' => 'JWTAuth',
    'facade' => 'alias',
]);

To register a service provider, in the same file, scroll down to a relevant comment section and add the following line:

$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);

In your bootstrap/app.php, make sure you've un-commented:

$app->withFacades();

Then, register you class alias and check if it already exists (else your tests will break):

if (!class_exists('JWTAuth')) {
    class_alias('Tymon\JWTAuth\Facades\JWTAuth', 'JWTAuth');
}

To register your ServiceProvider, check your bootstrap/app.php:

/*
|--------------------------------------------------------------------------
| 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('App\Providers\AppServiceProvider');

// Add your service provider here
$app->register('Tymon\JWTAuth\Providers\JWTAuthServiceProvider');

Update #1

I made a simpel boilerplate here to integrate Lumen with JWT and Dingo.

Tags:

Laravel

Lumen