PHP code example of milpa / admin

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

    

milpa / admin example snippets


return [
    Milpa\Admin\AdminPlugin::class,
    // …your plugins
];

use Milpa\Admin\Section\{AdminSection, AdminSectionProvider};

final class InventoryPlugin implements PluginInterface, AdminSectionProvider
{
    public function adminSections(): array
    {
        return [
            // a dashboard primitive the panel already knows, with props
            new AdminSection(id: 'stock', title: 'Stock', component: 'metric-card',
                props: ['title' => 'Units in stock', 'value' => '1,204'], order: 30),

            // or a component you bring yourself — definition + renderer, registered under `component`
            new AdminSection(id: 'inventory', title: 'Inventory', component: 'inventory-table',
                definition: new InventoryComponent($repo), renderer: new InventoryRenderer(), order: 31),
        ];
    }
}

new AdminSection(
    id: 'reports', title: 'Reports', component: 'metric-card',
    props: ['title' => 'Reports', 'value' => '12'],
    order: 60, group: AdminSection::GROUP_APP, icon: '◈',
);

use Milpa\Admin\Section\AdminSection;
use Milpa\Admin\Section\DeclaredView;

AdminSection::ofView(
    id: 'agent',
    title: 'Agent',
    view: new DeclaredView(
        // Every ROOT is a Milpa element; ordinary HTML is allowed inside a component's node.
        markup: '<milpa:desktop-tabs id="agent-tabs"/><milpa:desktop-conversation id="agent-conversation"/>',
        definitions: ['desktop-tabs' => $tabs, 'desktop-conversation' => $conversation],
        renderers:   ['desktop-tabs' => $renderer, 'desktop-conversation' => $renderer],
        props:       ['desktop-conversation' => ['session' => $id]],   // per component, merged UNDER the markup's attributes
        signals:     ['desktop.tab' => 'chat'],                        // seeded into the page's ONE signals tag
        persist:     ['desktop.tab'],
        computed:    ['desktop.summary' => ['template' => '{desktop.turns} turns']],
    ),
    order: 60, group: AdminSection::GROUP_AGENT, icon: '◈',
);

// config/app.php
'live' => ['secret' => getenv('MILPA_LIVE_SECRET') ?: ''],

use Milpa\Runtime\Stack\{StackProviderInterface, ServiceDeclaration, PortMapping, EnvVar};

final class HubPlugin implements PluginInterface, StackProviderInterface
{
    public function services(): array
    {
        return [new ServiceDeclaration(
            name: 'mercure', image: 'dunglas/mercure',
            ports: [new PortMapping(container: 80, host: 3000)],
            env: [
                new EnvVar('SERVER_NAME', value: ':80'),
                new EnvVar('MERCURE_PUBLISHER_JWT_KEY', configKey: 'desktop.mercure.publisher_key', secret: true),
            ],
            summary: 'Pushes shell changes to the browser.',
        )];
    }
}

    return ['rooted' => ['<credential id>']];
   

   'admin' => ['middleware' => [\Milpa\AppRuntime\Web\PasskeyGateMiddleware::class]],
   
bash
   php bin/coa identity:bootstrap --scopes=identity:enroll --sign
   
bash
   php bin/coa identity:enroll --fingerprint=<credential id> --scopes=milpa.admin --sign