ReflectionException - Middleware class does not exist Laravel 5.2
<p>I am building an API with stateless HTTP basic authentication in Laravel 5.2, as per documentation <a href="https://laravel.com/docs/5.1/authentication#stateless-http-basic-authentication" rel="noreferrer">Stateless HTTP Basic Authentication </a>, I have created following Middleware</p>

<p>app/Http/Middleware/AuthenticateOnceWithBasicAuth.php</p>

<pre><code>&lt;?php

namespace Illuminate\Auth\Middleware;

use Auth;
use Closure;

class AuthenticateOnceWithBasicAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    public function handle($request, Closure $next)
    {
        return Auth::onceBasic() ?: $next($request);

    }

}
</code></pre>

<p>And then registered it in Kernel.php </p>

<p>app/Http/kernel.php</p>

<pre><code>protected $routeMiddleware = [
    'auth' =&gt; \App\Http\Middleware\Authenticate::class,
    'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'can' =&gt; \Illuminate\Foundation\Http\Middleware\Authorize::class,
    'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
    'auth.basic.once' =&gt; \App\Http\Middleware\AuthenticateOnceWithBasicAuth::class,
];
</code></pre>

<p>I am using it in route as follows</p>

<pre><code>Route::group(['prefix' =&gt; 'admin', 'middleware' =&gt; 'auth.basic.once'], function () {

Route::get('service/create', function ()    {
    return response()-&gt;json(['name' =&gt; 'Abigail', 'state' =&gt; 'CA'], 200);
});

});
</code></pre>

<p>But it is giving me </p>

<p>ReflectionException in Container.php line 734:
Class App\Http\Middleware\AuthenticateOnceWithBasicAuth does not exist</p>

<p><a href="https://i.stack.imgur.com/kDm9f.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kDm9f.png" alt="enter image description here"></a></p>

<p>I have run following commands but with no success </p>

<pre><code>composer dump-autoload
php artisan clear-compiled
php artisan optimize 
</code></pre>

<p>Any help would be much appreciated. Thanks in advance.</p>