1. Go to this page and download the library: Download erjanmx/laravel-api-auth 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/ */
erjanmx / laravel-api-auth example snippets
return [
'services' => [
'MY_APP' => [ // this is the name of the middleware of route group to be protected
'tokenName' => 'api_token', // name of key that will be checked for secret value
'token' => env('MY_APP_TOKEN'), // secret value that is retrieved from env vars and needs to be passed in requests in order to get access to your protected urls
'allowJsonToken' => true,
'allowBearerToken' => true,
'allowRequestToken' => true,
]
],
];
Route::group(['prefix' => 'api', 'middleware' => ['apiauth:MY_APP']], function () { // note the `MY_APP` that should match the name in your config we changed above
Route::any('/', function () {
return 'Welcome!';
});
});