PHP code example of arubacao / http-basic-auth-guard

1. Go to this page and download the library: Download arubacao/http-basic-auth-guard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arubacao / http-basic-auth-guard example snippets


// bootstrap/app.php

// Uncomment the following line 
 $app->register(App\Providers\AuthServiceProvider::class);

// bootstrap/app.php

// Uncomment the following lines
 $app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
 ]);

// bootstrap/app.php

// Uncomment the following lines
 $app->withFacades();
 $app->withEloquent();


// bootstrap/app.php

// Add the following line
$app->register(Arubacao\BasicAuth\BasicGuardServiceProvider::class);

// config/auth.php
'guards' => [
    'api' => [
        'driver' => 'basic',
        'provider' => 'users'
    ],

    // ...
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
    ],
],

Route::get('api/whatever', ['middleware' => 'auth:api', 'uses' => 'NiceController@awesome']);



namespace App\Http\Controllers;

class NiceController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api');
    }
}