草庐IT

php - 流明:jwt-auth 不存在方法句柄,已完成中间件

coder 2024-04-15 原文

嘿,所以我刚刚更新到 Lumen 5.2 并遇到了 jwt-auth 的问题。我已按照所有说明更新了我的 app.php 文件,包括所有中间件。我还 Composer 需要照明/路由和照明/授权。 但是我得到了错误:

Macroable.php 第 81 行中的 BadMethodCallException: 方法句柄不存在。在 Macroable.php 第 81 行的 ResponseFactory->__call('handle', array(object(Request), object(Closure)))

我似乎无法从那个错误中得到任何意义?

这是我的 boostrap/app.php 供引用:

<?php

require_once __DIR__.'/../vendor/autoload.php';

try {
    (new Dotenv\Dotenv(__DIR__.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
    //
}

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

//$app = new Laravel\Lumen\Application(
//    realpath(__DIR__.'/../')
//);

// For nested route groups to work
$app = new Fremail\NestedRouteGroups\Application(
    realpath(__DIR__.'/../')
);

 $app->withFacades();

$app->configure('jwt');
$app->configure('auth');

class_alias(Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTAuth');
class_alias(Tymon\JWTAuth\Facades\JWTFactory::class, 'JWTFactory');


 $app->withEloquent();

/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Cache\CacheManager::class,
    function ($app) {
        return $app->make('cache');
    }
);

$app->singleton(
    Illuminate\Auth\AuthManager::class,
    function ($app) {
        return $app->make('auth');
    }
);

$app->singleton(
    Illuminate\Contracts\Routing\ResponseFactory::class,
    Illuminate\Routing\ResponseFactory::class
);


/*
|--------------------------------------------------------------------------
| 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([
    Illuminate\Contracts\Routing\ResponseFactory::class,
//     // Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
//     // Illuminate\Session\Middleware\StartSession::class,
//     // Illuminate\View\Middleware\ShareErrorsFromSession::class,
//    Laravel\Lumen\Http\Middleware\VerifyCsrfToken::class,
 ]);

// Middleware for authentication for the API
$app->routeMiddleware([
    'auth'        => App\Http\Middleware\Authenticate::class,
    'jwt.auth'    => Tymon\JWTAuth\Middleware\GetUserFromToken::class,
    'jwt.refresh' => Tymon\JWTAuth\Middleware\RefreshToken::class,
]);

/*
|--------------------------------------------------------------------------
| 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\GuardServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class);

/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
    require __DIR__.'/../app/Http/routes.php';
});

return $app;

谢谢你的帮助

最佳答案

我的回答肯定晚了,但对于 future 的 googlers,我是这样解决的(Lumen 5.3):

我在 bootstrap/app.php 中设置了 auth 中间件:

$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class
]);

关于php - 流明:jwt-auth 不存在方法句柄,已完成中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37448883/

有关php - 流明:jwt-auth 不存在方法句柄,已完成中间件的更多相关文章

  1. ruby-on-rails - rspec - 如何检查方法是否存在? - 2

    我的模型有defself.empty_building//stuffend我怎样才能对这个现有的进行rspec?,已经尝试过:describe"empty_building"dosubject{Building.new}it{shouldrespond_to:empty_building}endbutgetting:Failure/Error:it{shouldrespond_to:empty_building}expected#torespondto:empty_building 最佳答案 你有一个类方法self.empty_bu

  2. ruby-on-rails - ActiveRecord 的 find_or_create* 方法是否存在根本性缺陷? - 2

    有几种方法:first_or_create_by、find_or_create_by等,它们的工作原理是:与数据库对话以尝试找到我们想要的东西如果我们找不到,就自己做保存到数据库显然,并发调用这些方法可能会使两个线程都找不到它们想要的东西,并且在第3步中一个线程会意外失败。似乎更好的解决方案是,创建或查找即:提前在您的数据库中创建合理的唯一性约束。如果你想保存一些东西,就保存它如果有效,那就太好了。如果它因为RecordNotUnique异常而无法工作,它已经存在,太好了,加载它那么在什么情况下我想使用Rails内置的东西而不是我自己的(看起来更可靠)create_or_find?

  3. ruby - 检查网络文件是否存在,而不下载它? - 2

    是否可以在不实际下载文件的情况下检查文件是否存在?我有这么大的(~40mb)文件,例如:http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm这与ruby​​不严格相关,但如果发件人可以设置内容长度就好了。RestClient.get"http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm",headers:{"Content-Length"=>100} 最佳答案

  4. ruby-on-rails - 如果存在则更新,否则什么也不做? - 2

    当且仅当模型存在时,我才尝试更新模型的值。如果没有,我什么都不做。搜索似乎只返回更新或创建问题/答案,但我不想创建。我知道我可以用一个简单的方法来做到这一点:found=Model.find_by_id(id)iffoundupdatestuffend但是,我觉得有一种方法可以在一次调用中完成此操作,而无需分配任何临时本地值或执行if。如果记录不存在,我该如何编写一个Rails调用来更新记录而不出现嘈杂错误?最新的Rails3.x 最佳答案 您可以使用try在对find_by_id或where的结果调用update_attribut

  5. ruby - 如何使用 Ruby 检查域是否存在? - 2

    类似的东西:defdomain_exists?(domain)#performcheck#returntrue|falseendputs"valid!"ifdomain_exists?("example.com") 最佳答案 require'socket'defdomain_exists?(domain)beginSocket.gethostbyname(domain)rescueSocketErrorreturnfalseendtrueend 关于ruby-如何使用Ruby检查域是否存

  6. ruby-on-rails - 检查 Rails/Ruby 中对象是否存在的正确方法是什么? - 2

    我有很多模型和关系。由于这个事实,在View/Controller中有很多调用,看起来像这样:@object.something.with_something.value链的某些部分最终可能为零,这完全没问题。检查终端对象是否存在的正确/干净/快速的方法是什么?正在调用类似的东西:@object.something.with_something.valueifdefined?@object.something.with_something.value还可以吗? 最佳答案 在本地,您需要使用&&运算符(不是defined?),但这很快

  7. ruby - 如果键存在,向散列值添加一些东西? - 2

    我在Ruby中有一个哈希:hash=Hash.new里面有一些键值对,比如说:hash[1]="One"hash[2]="Two"如果散列包含键2,那么我想将“Bananas”添加到它的值中。如果散列没有键2,我想创建一个新的键值对2=>"Bananas"。我知道我可以通过首先使用has_key?检查散列是否具有key2来做到这一点,然后采取相应的行动。但这需要一个if语句和不止一行。那么是否有一种简单、优雅的单行代码可以实现这一目标? 最佳答案 这个有效:hash[2]=(hash[2]||'')+'Bananas'如果您希望所有

  8. ruby-on-rails - Rails 4.1 Devise 3.3 列 users.password 不存在 - 2

    我想通过控制台手动创建一个用户:User.find_or_create_by(email:"user@mail.com",first_name:"Stan",last_name:"Smith",password:"password",password_confirmation:"password",confirmed_at:Time.now)我在过去的项目中多次这样做,但这次没有用。它没有获取Devise密码模型属性,所以这是我得到的错误:PG::UndefinedColumn:ERROR:columnusers.passworddoesnotexist我有Rails4.1.4和Dev

  9. ruby-on-rails - 这个 C 和 PHP 程序员如何学习 Ruby 和 Rails? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它

  10. ruby-on-rails - Rails 存在吗?不区分大小写 - 2

    Model.exists?("lower(email)=?",params[:email].downcase)返回错误:ArgumentError(参数数量错误(2代表0..1)):是否可以使用不区分大小写的匹配来执行exists?? 最佳答案 您需要做的就是:Model.exists?(["lower(email)=?",params[:email].downcase])它正在寻找一个参数,但您提供了两个。使用数组形式和查找式条件应该可以满足您的需求。 关于ruby-on-rails-

随机推荐