2017-04-14 89 views
1

我看了一下每一個在Laravel與這個錯誤後:缺少參數1照亮\ \支持管理:: createDriver()

Missing argument 1 for Illuminate Support Manager - createDriver()

2th link

3th link

他們都沒有解決我的問題:我正在使用Laravel流明版本5.4和Dingo API package

我要訪問的身份驗證的用戶傳入的請求:

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

然而,這將引發我一個錯誤說:

缺少參數1照亮的\ Support \管理:: createDriver(),在/var/www/html/myApp/vendor/illuminate/support/Manager.php在線88中調用並定義「,

我知道,爲了ge t爲身份驗證的用戶,您需要提供身份驗證中間件路由裏面:

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

但添加的中間件驗證我的路線裏面實際上沒有達到控制器端點扔,你可以在上面看到的同樣的錯誤。

我有AuthServiceProvider在我的引導/ app.php註冊:

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

這是我在配置/ 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, 
    ], 
], 

]; 

我試圖自己調試這個問題,我發現這是它在破碎的地方Lar AVEL:

/** 
* 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."); 
} 

我可以在堆棧跟蹤看到,它被傳遞NULL驅動器內部createDriver引起我正在具有的誤差()方法。我不知道這是不是一個簡單的配置,我必須在我的.env文件中添加。

我從Laravel Lumen開始,這是一個非常棒的工具,用於構建API,我不會責怪這個工具本身(我花了很多時間閱讀美麗的文檔),我很確定我錯過了一些東西簡單的說,如果有人能指導我這個,我會很高興。

+0

您是否在'bootstrap/app.php'中取消了'$ app-> routeMiddleware()'調用的註釋。 –

+0

@PankitGami是的,我在bootstrap> app.php中有這行:$ app-> routeMiddleware([ 'auth'=> App \ Http \ Middleware \ Authenticate :: class, ]); –

+0

是評論還是取消評論? –

回答

0

你使用Laravel Scout(與Algolia搜索驅動程序)?

我遇到了運行我的數據庫種子時看到的錯誤。最後,我意識到我疲憊的心靈忘了在我的作品中定義正確的env變量。ENV文件,如下圖所示:

PHP工匠供應商:發佈 --provider =「Laravel \

SCOUT_DRIVER=algolia 
ALGOLIA_APP_ID=yourAlgoliaAppId 
ALGOLIA_SECRET=yourAlgoliaSecret 

如果您還沒有公佈偵察配置文件,用下面的命令這樣做偵察員\ ScoutServiceProvider」

確保你已經把‘Laravel \斥候\ ScoutServiceProvider ::類’中‘配置/ app.php’提供一個存儲在運行上述命令。

一旦我出版的配置文件(默認情況下名爲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'), 
    ], 

]; 

一旦我做了所有上述情況,錯誤就走開了。此答案可能不會直接解決您的確切問題,但它可能會給您提供想法或幫助您排除故障。