缺少Illuminate \\ Support \\ Manager :: createDriver()

时间:2017-04-14 10:45:47

标签: laravel laravel-5.4 lumen laravel-middleware

我查看了Laravel中与此错误相关的每篇帖子:

Missing argument 1 for Illuminate Support Manager - createDriver()

2th link

3th link

他们都没有解决我的问题:我使用的是Laravel Lumen版本5.4和Dingo API package

我想访问传入请求中的Authenticated User:

 $request->user(); //returns an instance of the authenticated user

然而,这会让我误以为:

  

缺少Illuminate \ Support \ Manager :: createDriver()的参数1,在第88行的/var/www/html/myApp/vendor/illuminate/support/Manager.php中调用并定义了“,

我知道为了获得Authenticated User,您需要在路由中提供Auth Middleware:

  $api->get('register/{accountId}', ['middleware' => 'auth', 'App\Http\Controllers\Api\V1\RegisterController@registerAction']);

但是在我的路线中添加Middleware Auth实际上不会到达Controller端点并抛出您在上面看到的相同错误。

我在我的bootstrap / app.php中注册了AuthServiceProvider:

 $app->register(App\Providers\AuthServiceProvider::class);

这是AuthServiceProvider类:

 <?php

 namespace App\Providers;

 use App\Models\Account;
 use Illuminate\Support\ServiceProvider;

 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.

    $this->app['auth']->viaRequest('api', function ($request) {

        if ($request->input('api_token')) {
            return Account::where('api_token', $request->input('api_token'))->first();
        }
    });
   }
  }

这就是我在config / auth.php中所拥有的:

  <?php

  return [

/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/

'defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],

/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
],

/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/

'passwords' => [
    'users' => [
        'provider' => 'users',
        'table' => 'password_resets',
        'expire' => 60,
    ],
 ],

];

我试图自己调试这个问题,但我发现这是Laravel破解的地方:

/**
 * Create a new driver instance.
 *
 * @param  string  $driver
 * @return mixed
 *
 * @throws \InvalidArgumentException
 */
protected function createDriver($driver)
{
    // We'll check to see if a creator method exists for the given driver. If not we
    // will check for a custom driver creator, which allows developers to create
    // drivers using their own customized driver creator Closure to create it.
    if (isset($this->customCreators[$driver])) {
        return $this->callCustomCreator($driver);
    } else {
        $method = 'create'.Str::studly($driver).'Driver';

        if (method_exists($this, $method)) {
            return $this->$method();
        }
    }
    throw new InvalidArgumentException("Driver [$driver] not supported.");
}

我可以在stackTrace中看到它在createDriver()方法中传递NULL驱动程序,这会导致我遇到的错误。我想知道这不是一个简单的配置,我必须在我的.env文件中添加。

我从Laravel Lumen开始,它是构建API的一个很好的工具,我不会责怪工具本身(我花了很多时间阅读漂亮的文档),我很确定我错过了很简单的东西如果有人可以指导我,我会很高兴。

1 个答案:

答案 0 :(得分:0)

您使用Laravel Scout(使用Algolia搜索驱动程序)吗?

我遇到了您在运行数据库种子时看到的错误。最后,我意识到我的疲惫心灵忘了在我的.env文件中定义正确的env变量,如下所示:

SCOUT_DRIVER=algolia
ALGOLIA_APP_ID=yourAlgoliaAppId
ALGOLIA_SECRET=yourAlgoliaSecret

如果您尚未发布scout配置文件,请使用以下命令执行此操作:

  

php工匠供应商:发布   --provider = “Laravel \侦察\ ScoutServiceProvider”

在运行上述命令之前,请确保已在'config / app.php'的providers数组中放入'Laravel \ Scout \ ScoutServiceProvider :: class'。

我发布配置文件(默认名为config / scout.php)后,我使用了env变量,如下所示:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Search Engine
    |--------------------------------------------------------------------------
    |
    | This option controls the default search connection that gets used while
    | using Laravel Scout. This connection is used when syncing all models
    | to the search service. You should adjust this based on your needs.
    |
    | Supported: "algolia", "elasticsearch", "null"
    |
    */

    'driver' => env('SCOUT_DRIVER'),

    /*
    |--------------------------------------------------------------------------
    | Index Prefix
    |--------------------------------------------------------------------------
    |
    | Here you may specify a prefix that will be applied to all search index
    | names used by Scout. This prefix may be useful if you have multiple
    | "tenants" or applications sharing the same search infrastructure.
    |
    */

    'prefix' => env('SCOUT_PREFIX', ''),

    /*
    |--------------------------------------------------------------------------
    | Queue Data Syncing
    |--------------------------------------------------------------------------
    |
    | This option allows you to control if the operations that sync your data
    | with your search engines are queued. When this is set to "true" then
    | all automatic data syncing will get queued for better performance.
    |
    */

    'queue' => false,

    /*
    |--------------------------------------------------------------------------
    | Algolia Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure your Algolia settings. Algolia is a cloud hosted
    | search engine which works great with Scout out of the box. Just plug
    | in your application ID and admin API key to get started searching.
    |
    */

    'algolia' => [
        'id' => env('ALGOLIA_APP_ID'),
        'secret' => env('ALGOLIA_SECRET'),
    ],

];

完成上述所有操作后,错误就消失了。这个答案可能无法直接解决您的确切问题,但它可能会给您提供想法或帮助您进行故障排除。