Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to register Facades & Service Providers in Lumen

Tags:

laravel

lumen

I Am looking for where to add the facade below in Lumen.

'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth' 

EDITED

Also where to register service provider in bootstrap\app.php

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

Please assist.

like image 735
Emeka Mbah Avatar asked May 22 '15 14:05

Emeka Mbah


People also ask

What is a facade in PHP?

Facade is a structural design pattern that provides a simplified (but limited) interface to a complex system of classes, library or framework. While Facade decreases the overall complexity of the application, it also helps to move unwanted dependencies to one place.

What is DB facade?

The DB facade provides methods for each type of query: select , update , insert , delete , and statement .

What does Laravel use for seeding & facades?

Laravel includes the ability to seed your database with data using seed classes. All seed classes are stored in the database/seeders directory. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.


2 Answers

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.

like image 73
krisanalfa Avatar answered Sep 20 '22 12:09

krisanalfa


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); 
like image 43
qwaz Avatar answered Sep 19 '22 12:09

qwaz