PHP code example of edgebase / admin

1. Go to this page and download the library: Download edgebase/admin 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/ */

    

edgebase / admin example snippets




use EdgeBase\Admin\AdminClient;

$admin = new AdminClient(
    'https://your-project.edgebase.fun',
    getenv('EDGEBASE_SERVICE_KEY') ?: ''
);

$users = $admin->adminAuth->listUsers(limit: 20);

$postRows = $admin->sql(
    'shared',
    null,
    'SELECT id, title FROM posts WHERE status = ?',
    ['published']
);

$bucket = $admin->storage->bucket('avatars');
$bucket->upload('user-1.jpg', 'binary-data', contentType: 'image/jpeg');

$admin->push()->send('user-1', [
    'title' => 'Deployment finished',
    'body' => 'Your content is live.',
]);

$posts = $admin->db('app')->table('posts');
$rows = $posts->where('status', '==', 'published')->get();

$admin->db('workspace', 'ws-123');
$admin->db('user', 'user-123');

$created = $admin->adminAuth->createUser([
    'email' => '[email protected]',
    'password' => 'secure-pass-123',
    'displayName' => 'June',
]);

$admin->adminAuth->setCustomClaims($created['id'], [
    'role' => 'moderator',
]);

$users = $admin->adminAuth->listUsers(limit: 20);

$sharedRows = $admin->sql('shared', null, 'SELECT 1 AS ok');

$workspaceRows = $admin->sql(
    'workspace',
    'ws-123',
    'SELECT * FROM documents WHERE status = ?',
    ['published']
);

$admin->push()->send('user-123', [
    'title' => 'Hello',
    'body' => 'From the admin SDK',
]);

$overview = $admin->analytics()->overview(['range' => '7d']);