简体   繁体   English

调用流明中未定义的方法Closure :: group()

[英]Call to undefined method Closure::group() in Lumen

New to Lumen Vuejs here. Lumen Vuejs的新功能在这里。

I have a problem regarding the connection between 2 frameworks particularly to generating tokens. 我对2个框架之间的连接有疑问,尤其是在生成令牌方面。

This is my App.php 这是我的App.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__.'/../')
);

$app->withFacades();

$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
);

/*
|--------------------------------------------------------------------------
| 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([
    App\Http\Middleware\ExampleMiddleware::class,
    palanik\lumen\Middleware\LumenCors::class
]);

$app->routeMiddleware([
   'auth' => App\Http\Middleware\Authenticate::class,
   'cors' => palanik\lumen\Middleware\LumenCors::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\AppServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::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__.'/../routes/web.php';
});

return $app;

and this is my AuthServiceProvider.php 这是我的AuthServiceProvider.php

<?php

namespace App\Providers;

use App\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Dusterio\LumenPassport\LumenPassport;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * 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.

        // Dusterio\LumenPassport\LumenPassport::routes($app);
        LumenPassport::routes();

        $this->app['auth']->viaRequest('api', function ($request) {
            if ($request->input('api_token')) {
                return User::where('api_token', $request->input('api_token'))->first();
            }
        });
    }
}

The problem here is found on the AuthServiceProvider.php file. 在AuthServiceProvider.php文件中找到此处的问题。 I have used this package https://github.com/dusterio/lumen-passport for passport, and https://github.com/palanik/lumen-cors for cross origin of HTTP requests and i have no idea where is the error is really happening even if i am properly following the documentations of 2 packages has been done exactly. 我已经使用这个包https://github.com/dusterio/lumen-passport护照,并https://github.com/palanik/lumen-cors HTTP请求的十字起源和我不知道哪里出了错误即使我正确地按照2个软件包的文档进行了准确地设置,这确实在发生。

Your response is much appreciated! 非常感谢您的回复!

You probably use Lumen 5.5. 您可能会使用Lumen 5.5。

dusterio\\lumen-passport is currently NOT compatible with Lumen 5.5 (as per 5 oct 2017) (see https://github.com/dusterio/lumen-passport/pull/53 ) dusterio\\lumen-passport当前与Lumen 5.5不兼容(截至2017年10月5日)(请参阅https://github.com/dusterio/lumen-passport/pull/53

Either downgrade to Lumen 5.4 or wait for this package to be updated. 降级到Lumen 5.4或等待此程序包被更新。

Try this: 尝试这个:

  1. Open AuthServiceProvider.php in your app/Providers folder, add 在您的app / Providers文件夹中打开AuthServiceProvider.php,添加

     use Dusterio\\LumenPassport\\LumenPassport; 
  2. Inside the boot() function, add: 在boot()函数中,添加:

     LumenPassport::routes($this->app->router, ['prefix' => 'v1/oauth']); 

If you do not want prefix then you can delete it. 如果您不希望使用前缀,则可以将其删除。

Just found a solution. 刚刚找到解决方案。

Call - 致电-

   Dusterio\LumenPassport\LumenPassport::routes($app);

in bootstrap/app.php after registering Passport service providers rather than calling LumenPassport::routes(); 在注册Passport服务提供商之后而不是调用LumenPassport :: routes()之后在bootstrap / app.php中 in AppServiceProvider as defined in docs. 在docs中定义的AppServiceProvider中。

Then, go to - 然后,转到-

   <app_source>/vendor/dusterio/lumen-passport/src/LumenPassport.php

Search for routes function 搜索路线功能

   public static function routes($callback = null, array $options = [])
   {
      ...
   }

Look for - 寻找 -

   $callback->group($options, function ($router) use ($callback) {
        ...
    });

Change - 变更-

    $callback->group(...) to $callback->route->group(...)

That solves the issue completely. 那完全解决了问题。

我认为是$callback->router->group

Look at fresh lumen project bootstrap/app.php 看看新鲜的流明项目bootstrap/app.php

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

return $app;

Lumen changed the way to define routes. 流明改变了定义路线的方式。 So, use the new way. 因此,请使用新方法。

  • Old: $app->group 旧: $app->group
  • New: $app->route->group 新增: $app->route->group

Refer Lumen 5.5 - Route Group 参考流明5.5-路线组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 流明中的路由组错误调用未定义的方法Laravel \\ Lumen \\ Application :: group() - Route Group in Lumen error Call to undefined method Laravel\Lumen\Application::group() 调用未定义的方法Closure :: query() - Call to undefined method Closure::query() 调用未定义的方法Closure :: getName() - Call to undefined method Closure::getName() 流明5.3未定义变量:关闭 - Lumen 5.3 Undefined variable: closure 调用未定义的方法 Laravel\\Lumen\\Routing\\Router::prefix() - Call to undefined method Laravel\Lumen\Routing\Router::prefix() 调用未定义的方法 Laravel\Lumen\Routing\Router::pos() - call to undefined method Laravel\Lumen\Routing\Router::pos() 致命错误:未捕获错误:调用未定义的方法 Closure::index() php - Fatal error: Uncaught Error: Call to undefined method Closure::index() php Lumen:在 routes.php 第 17 行:升级到 5.5 后调用未定义的方法 Laravel\Lumen\Application::post()。* - Lumen: In routes.php line 17: Call to undefined method Laravel\Lumen\Application::post(), after upgrade to 5.5.* 未定义的方法 Laravel\Lumen\Application::booted() - Undefined method Laravel\Lumen\Application::booted() 在流明中的路由控制器中模拟方法调用以进行测试 - Mocking a method call in a route controller in Lumen for testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM