Skip to content

Docs ‐ Menu

papamarfo edited this page Jul 30, 2026 · 3 revisions

Introduction to Menu

USSD menus although simple, can spiral out of handle quickly. Laravel USSD provides a class to help you create an easy-to-maintain menu.

Creating Menu

<?php

use Speso\Ussd\Menu;

Menu::build()
    ->text('Choose One')
    ->lineBreak(2)
    ->listing(['Mango', 'Pear'])
    ->when(false, fn (Menu) => $menu->line('Next'))
    ->prepend(fn (Menu) => $menu->line('Generated with Laravel USSD'))
    ->append(fn (Menu) => $menu->lineBreak()->format('Powered by %s', 'Speso'));

// Generated with Laravel USSD
// Choose One
// 
// 1.Mango
// 2.Pear
// 
// Powered by Speso

Localizing Menus

Menu also provides trans, transLine and transChoice, which build menu content from your app's translation files (lang/{locale}/...) instead of hardcoded strings, so the same flow can serve multiple languages.

<?php

use Speso\Ussd\Menu;

Menu::build()
    ->transLine('ussd.welcome')
    ->transChoice('ussd.items_count', $count = 3, ['count' => $count]);

A session's language choice can be persisted with Record::setLocale() so it's applied automatically on every following request — see Docs ‐ Record for details.

Clone this wiki locally