35

我正在寻找在 Lumen 下面添加立面的位置。

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

已编辑

还有在哪里注册服务提供商bootstrap\app.php

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

请协助。

4

3 回答 3

64

在您的bootstrap/app.php中,确保您已取消注释:

$app->withFacades();

然后,注册你的类别名并检查它是否已经存在(否则你的测试会中断):

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

要注册您的ServiceProvider,请检查您的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');

更新#1

我在这里制作了一个简单的样板来将 Lumen 与 JWT 和 Dingo 集成。

于 2015-05-22T15:37:41.183 回答
21

要使用 alias 注册外观,请转到bootstrap/app.php并取消注释:

$app->withFacades();

...它指示框架从外观开始。要添加外观,只需将它们放在一个数组中并将数组作为第二个参数传递,同时将第一个参数设置为true,如下所示:

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

要注册服务提供者,在同一个文件中,向下滚动到相关评论部分并添加以下行:

$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);
于 2017-07-19T09:28:46.713 回答
3

在你的 bootstrap\app.php

提供者示例

// XML parser service provider
$app->register(\Nathanmac\Utilities\Parser\ParserServiceProvider::class);
// GeoIP
$app->register(\Torann\GeoIP\GeoIPServiceProvider::class);
$app->withEloquent();

别名示例

// SERVICE ALIASES
class_alias(\Nathanmac\Utilities\Parser\Facades\Parser::class, 'Parser');
class_alias(\Torann\GeoIP\Facades\GeoIP::class, 'GeoIP');
$app->withFacades();
...
...
...

祝你好运

于 2018-06-17T11:56:36.527 回答