2017-04-14 23 views
1

私はLaravelで、このエラーに関連するすべてのポストを見ていた:欠落引数1 :: createDriver()

Missing argument 1 for Illuminate Support Manager - createDriver()

2th link

3th link

誰も私の問題を解決しませんでした:私はLaravel Lumenバージョン5.4とDingo API packageを使用しています。私は着信要求に認証されたユーザーにアクセスしたい

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

は、しかし、これは言って私にエラーがスローされます。

が点灯\サポート\ Managerの引数1がありません::ライン88上の/var/www/html/myApp/vendor/illuminate/support/Manager.phpに呼び出され、」定義されたcreateDriver()、、

は、私が知っているために、GEへ認証されたユーザーT、あなたは、ルーティング内の認証ミドルウェアを提供する必要があります。

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

しかし、私のルート内のミドルウェア認証を追加すると、実際にコントローラのエンドポイントに到達し、あなたは上記を参照することができ、同じエラーがスローされません。

私は私のブートストラップ/ 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(); 
     } 
    }); 
    } 
    } 

これは私が設定/ 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で壊れていることがわかりましたキブロン:

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

私はそれは私がいるエラーを引き起こすcreateDriver()メソッド内でNULLドライバーを渡していることをスタックトレースで見ることができます。 .envファイルの中に追加しなければならない単純な設定ではないかと思います。私はLaravelルーメンで始めています

は、それがAPIを構築するための素晴らしいツールだと私はツール自体(私は美しいドキュメントを読んで多くの時間を要した)、私は私が何かを非常に逃したことをかなり確信していると非難していませんよ単純な、誰かが私にこれを導くことができれば、私は非常に満足しています。

+0

'bootstrap/app.php'で' $ app-> routeMiddleware() 'のコメントを外しましたか? –

+0

@PankitGamiはい、私はbootstrap> app.phpに次の行を持っています:$ app-> routeMiddleware( 'auth' => App \ Http \ Middleware \ Authenticate :: class、 ]); –

+0

コメントやコメントは解除されていますか? –

答えて

0

Laravel ScoutAlgolia検索ドライバ)を使用していますか?

データベースシードの実行中に表示されたエラーに遭遇しました。最後に、私の疲れた心は私の中で正しいenv変数を定義することを忘れていたことに気付きました。以下のようにENVファイル:

PHPの職人ベンダー: --provider = "Laravel \を公開あなたはスカウト設定ファイルを公開していない場合は

SCOUT_DRIVER=algolia 
ALGOLIA_APP_ID=yourAlgoliaAppId 
ALGOLIA_SECRET=yourAlgoliaSecret 

は、以下のコマンドでそれを行いますスカウト\ ScoutServiceProvider」

は、上記のコマンドを実行する前に、 『設定/ app.php』内のプロバイダの配列に 『Laravel \スカウト\ ScoutServiceProvider ::クラス』を入れていることを確認してください。

私は(デフォルトで設定/ 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'), 
    ], 

]; 

私は上記のすべてをやったら、エラーが去っていきました。この回答はあなたの正確な問題に直接対処できないかもしれませんが、おそらくあなたの考えを与えるか、トラブルシューティングプロセスを助けるかもしれません。

関連する問題