title: How to add a custom User Provider in Laravel 5.4
body: <p>I have a Laravel 5.4 app, in which I have to authenticate my admin users from an external API, which when successfully logged in it returns a JSON with user information. </p>
  
  <p>I am creating a custom guard to make this:</p>
  
  <pre><code>    'guards' =&gt; [
          'web' =&gt; [
              'driver' =&gt; 'session',
              'provider' =&gt; 'users'
          ],
  
          'custom' =&gt; [
              'driver' =&gt; 'session',
              'provider' =&gt; 'customusers'
          ],
  
          'api' =&gt; [
              'driver' =&gt; 'token',
              'provider' =&gt; 'users',
          ],
      ],
  </code></pre>
  
  <p>and this is my custom provider:</p>
  
  <pre><code>'providers' =&gt; [
      'users' =&gt; [
          'driver' =&gt; 'eloquent',
          'model' =&gt; App\User::class,
      ],
  
      'customusers' =&gt; [
          'driver' =&gt; 'jsonresponse',
          'model' =&gt; App\Admin::class,
      ]
  ],
  </code></pre>
  
  <p>After that, I am not sure how to continue. I've read some tutorials like <a href="https://www.georgebuckingham.com/blog/laravel-52-auth-custom-user-providers-drivers/" rel="noreferrer">the one from George Buckingham</a>, and I have created a custom User provider (Right now I just need it to extend from EloquentUserProvider, eventually I will override some functions to connect to the API)</p>
  
  <pre><code>&lt;?php
  
  namespace App\Providers;
  
  use Illuminate\Auth\EloquentUserProvider;
  use Illuminate\Support\Str;
  
  class CustomUserProvider extends EloquentUserProvider { 
  
  }
  </code></pre>
  
  <p>then registered it both in App\Providers\AuthServiceProvider</p>
  
  <pre><code>public function boot()
  {
      $this-&gt;registerPolicies();
  
      Auth::provider('jsonresponse', function($app, array $config) {
          return new CustomUserProvider($app['hash'], $config['model']);
      });
  }
  </code></pre>
  
  <p>and in config/app.php</p>
  
  <pre><code>'providers' =&gt; [
  
      // Lots of other providers
  
      // Own providers
      App\Providers\CustomUserProvider::class,
  ],
  </code></pre>
  
  <p>But after that, I get the following error: </p>
  
  <blockquote>
    <p>Argument 1 passed to
    Illuminate\Auth\EloquentUserProvider::__construct() must be an
    instance of Illuminate\Contracts\Hashing\Hasher, instance of
    Illuminate\Foundation\Application given, called in
    /var/www/public/iberorides/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
    on line 612 and defined</p>
  </blockquote>
  
  <p>If I override the constructor of my CustomUserProvider and change the params in the closure in AuthServiceProvider, I get the following error:</p>
  
  <blockquote>
    <p>Argument 1 passed to Illuminate\Foundation\Application::bootProvider()
    must be an instance of Illuminate\Support\ServiceProvider, instance of
    App\Providers\IberoUserProvider given, called in
    /var/www/public/iberorides/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
    on line 771 and defined</p>
  </blockquote>
  
  <p>This makes me think I am not doing things the right way. </p>
  
  <p>Could someone put me in the right direction?</p>
  
  <p>Thank you so much.</p>