Laravel - Authentication - Stateless Http Basic Authentication

You may also use HTTP Basic Authentication without setting a user identifier cookie in the session. This is primarily helpful if you choose to use HTTP Authentication to authenticate requests to your application's API. To accomplish this, define a middleware that calls the onceBasic method. If no response is returned by the onceBasic method, the request may be passed further into the application:


Next, register the route middleware and attach it to a route:

    Route::get('/api/user', function () {
        // Only authenticated users may access this route...