DocumentaciónDeveloper guideEjemplo completo
Hello Notes, paso a paso
Una pequeña aplicación que toca cada parte: un manifiesto, una tabla, rutas con inicio de sesión, dos páginas Vue, un valor de ajuste, sus propios permisos y su propio menú. Se instala desde un paquete firmado.
1 min de lectura
1. El manifiesto
<?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. La tabla
database/migrations/2027_04_01_000100_hello_create_notes.php. El nombre lleva hello_ después de la hora, como exige Tablas y modelos:
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();
});El modelo Models/HelloNote.php define $table = 'hello_notes' y $fillable = ['company_id', 'user_id', 'body'].
3. Rutas
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. El controlador
Cada acción comprueba el permiso correcto, lee solo las empresas del usuario y muestra una página hello:::
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 valida body, lo guarda bajo CompanyContext::defaultCompanyId() y redirige con UiText::t('Note saved.'). settings y saveSettings leen y escriben hello.greeting con ConfigParameter.
5. Las páginas
dist/addon.js está escrito a mano, así que el ejemplo no necesita ningún paso de compilación. Toma Vue, Inertia y el diseño del anfitrión y registra dos páginas:
(() => {
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 });
})();Los archivos completos se entregan junto a esta guía en Hello/.
6. Empaquetar, firmar, instalar
Siga Empaquetar y firmar y Instalar y activar. En el sistema de prueba donde se verificó esta guía, el paquete se generó con 6 archivos y se instaló desde Subir el paquete, y ambas páginas se abrieron.
Verificado en una instalación limpia del paquete de la versión OptiraPOS 1.0: el paquete firmado de Hello Notes se sube, se activa desde la línea de comandos y sus dos páginas se abren.