PHP code example of axolote-source / authxolote-sdk
1. Go to this page and download the library: Download axolote-source/authxolote-sdk 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/ */
Route::middleware('auth:authxolote')->get('/user', function (Request $request) {
return $request->user();
});
use Authxolote\Sdk\Authxolote;
// Check a single permission
if (Authxolote::action('edit-posts')->isAllow()) {
// User has permission
}
// Check multiple permissions (all must be allowed)
if (Authxolote::actions(['edit-posts', 'delete-posts'])->isAllowAll()) {
// User has all permissions
}
use Authxolote\Sdk\Authxolote;
$user = Authxolote::register(
'[email protected]',
'John Doe',
'password123',
'admin' // role key
);
use Authxolote\Sdk\Authxolote;
// Fake specific actions
Authxolote::actionsFake(['edit-posts']);
// Now this will return true without calling the API
Authxolote::action('edit-posts')->isAllow();
// This will return false
Authxolote::action('other-action')->isAllow();
Route::middleware(['auth:authxolote', 'isAllow:edit-posts'])->get('/posts/edit', function () {
// Only users with 'edit-posts' permission can access this
});
use App\Http\Controllers\TurnController;
use Illuminate\Support\Facades\Route;
Route::controller(TurnController::class)->group(function () {
Route::post('', 'store')->middleware('isAllow:gob.turn.store');
Route::get('/{id}', 'show')->middleware('isAllow:gob.turn.show');
Route::put('/{id}', 'update')->middleware('isAllow:gob.turn.update');
Route::delete('/{id}', 'delete')->middleware('isAllow:gob.turn.delete');
});