1. Go to this page and download the library: Download vinkla/shield 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/ */
declare(strict_types=1);
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
class BasicAuthMiddleware
{
public function handle(Request $request, Closure $next): Response
{
$user = config('auth.basic.user');
$password = config('auth.basic.password');
if (
$request->getUser() !== $user ||
$request->getPassword() !== $password
) {
throw new UnauthorizedHttpException('Basic');
}
return $next($request);
}
}
use App\Http\Middleware\BasicAuthMiddleware;
use App\Models\User;
Route::get('api/users', function () {
return User::all();
})->middleware(BasicAuthMiddleware::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.