/
WebsiteSupport

DocsDeveloper guideWorked example

Hello Notes, step by step

One small app that touches every part: a manifest, a table, signed-in routes, two Vue pages, a settings value, its own rights and menu. It installs from a signed package.

1 min read

1. The manifest

<?php
return [
    'slug' => 'hello',
    'name' => 'Hello Notes',
    'version' => '1.0.0',
    'requires' => ['optirapos' => '>=1.0.0'],
    'summary' => 'Short notes for your team, the developer guide example',
    'category' => 'Productivity',
    'author' => 'Your company',
    'depends' => [],
    'abilities' => ['key' => 'hello', 'label' => 'Hello Notes', 'abilities' => [
        ['key' => 'hello.view', 'label' => 'View'],
        ['key' => 'hello.manage', 'label' => 'Manage'],
    ]],
    'menu' => [[
        'key' => 'hello', 'label' => 'Hello Notes', 'icon' => 'M4 5h16M4 12h16M4 19h10',
        'ability' => 'hello.view', 'match' => ['/hello'],
        'groups' => [
            ['label' => 'Notes', 'items' => [['label' => 'Notes', 'href' => '/hello']]],
            ['label' => 'Configuration', 'items' => [['label' => 'Settings', 'href' => '/hello/settings']]],
        ],
        'sequence' => 50,
    ]],
    'segments' => ['hello' => ['hello.view']],
    'assets' => [],
];

2. The table

database/migrations/2027_04_01_000100_hello_create_notes.php. The name carries hello_ after the time, as Tables and models requires:

Schema::create('hello_notes', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('company_id')->index();
    $table->unsignedBigInteger('user_id')->nullable();
    $table->string('body', 500);
    $table->timestamps();
});

The model Models/HelloNote.php sets $table = 'hello_notes' and $fillable = ['company_id', 'user_id', 'body'].

3. Routes

Route::get('/hello', [HelloController::class, 'index'])->name('hello.index');
Route::post('/hello', [HelloController::class, 'store'])->name('hello.store');
Route::get('/hello/settings', [HelloController::class, 'settings'])->name('hello.settings');
Route::put('/hello/settings', [HelloController::class, 'saveSettings'])->name('hello.settings.save');

4. The controller

Every action checks the right ability, reads only the user's companies and renders a hello:: page:

public function index(Request $request)
{
    $this->allow($request, 'hello.view');   // isAdmin() || hasAbility(...), else 403
    return Inertia::render('hello::Index', [
        'greeting' => ConfigParameter::get('hello.greeting', 'Hello from your first add-on'),
        'notes' => HelloNote::query()->whereIn('company_id', CompanyContext::activeIds())
            ->latest('id')->limit(50)->get(['id', 'body', 'created_at']),
        'canManage' => $request->user()->isAdmin() || $request->user()->hasAbility('hello.manage'),
    ]);
}

store validates body, saves it under CompanyContext::defaultCompanyId() and redirects with UiText::t('Note saved.'). settings and saveSettings read and write hello.greeting with ConfigParameter.

5. The pages

dist/addon.js is written by hand, so the example needs no build step. It takes Vue, Inertia and the layout from the host and registers two pages:

(() => {
  const { h } = window.OptiraVendor.vue;
  const { useForm } = window.OptiraVendor.inertia;
  const Layout = window.OptiraVendor.ui.OptiraLayout;
  const Index = { props: { greeting: String, notes: Array, canManage: Boolean }, setup(props) {
    const form = useForm({ body: '' });
    return () => h(Layout, { title: 'Notes' }, () => h('div', { class: 'p-4' }, [
      h('p', props.greeting),
      /* a form posting form.post('/hello'), then the list of props.notes */
    ]));
  } };
  const Settings = { /* one field, saved with form.put('/hello/settings') */ };
  Object.assign(window.OptiraAddons.pages, { 'hello::Index': Index, 'hello::Settings': Settings });
})();

The full files ship beside this guide in Hello/.

6. Package, sign, install

Follow Package and sign and Install and activate. On the test system this guide was checked on, the package built as 6 files and installed from Upload package, and both pages opened.

Checked on a clean install of the OptiraPOS 1.0 release package: the signed Hello Notes package uploads, activates from the command line, and both of its pages open.

See also