1

I had a look at every post related to this error in Laravel:

Missing argument 1 for Illuminate Support Manager - createDriver()

2th link

3th link

None of them solved my issue: I am using Laravel Lumen version 5.4 and Dingo API package.

I want to access to the Authenticated User in the incoming request:

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

However this will throw me an error saying:

Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /var/www/html/myApp/vendor/illuminate/support/Manager.php on line 88 and defined",

I know that in order to get the Authenticated User, you need to provide the Auth Middleware inside the routing:

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

But adding the Middleware Auth inside my route will actually not reach the Controller endpoint and throw the same error that you can see above.

I have the AuthServiceProvider registered in my bootstrap/app.php:

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

And this is the AuthServiceProvider class:

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

This is what I have in 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,
    ],
 ],

];

I tried to debug the issue myself and I found out that this is where it is breaking in 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.");
}

I can see in the stackTrace that it is passing a NULL driver inside createDriver() method which cause the error that I'm having. I wonder if it is not a simple configuration thing that I have to add inside my .env file.

I am starting with Laravel Lumen, it's a great tool for building API and I'm not blaming the tool itself (I took a lot of time reading the beautiful documentation), I'm pretty sure that I missed something very simple, if someone can guide me to this, I will be very pleased.

Community
  • 1
  • 1
Nizar B.
  • 3,098
  • 9
  • 38
  • 56

1 Answers1

0

Are you using Laravel Scout (with Algolia search driver)?

I came across the errors you seen while running my database seeds. In the end, I realized my tired mind forgot to define the correct env variables in my .env file, as below:

SCOUT_DRIVER=algolia
ALGOLIA_APP_ID=yourAlgoliaAppId
ALGOLIA_SECRET=yourAlgoliaSecret

If you haven't published the scout config file, do so with the following command:

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

Make sure you have put 'Laravel\Scout\ScoutServiceProvider::class' in the providers array in 'config/app.php' before running the above command.

Once I published the config file (named config/scout.php by default), I used the env variables as below:

<?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'),
    ],

];

Once I did all of the above, the errors went away. This answer might not directly address your exact issue, but it could perhaps give you thoughts or aid your troubleshooting process.

Rob
  • 1,272
  • 6
  • 24
  • 35