Dialog
NativePHP for Desktop and Mobile have reached v1!
#Overview
The Dialog API provides access to native UI elements like alerts, toasts, and sharing interfaces.
Copied!
use Native\Mobile\Facades\Dialog;
#Methods
#alert()
Displays a native alert dialog with customizable buttons.
Parameters:
string $title
- The alert titlestring $message
- The alert messagearray $buttons
- Array of button labels (max 3 buttons)
Button Positioning:
- 1 button - Positive (OK/Confirm)
- 2 buttons - Negative (Cancel) + Positive (OK/Confirm)
- 3 buttons - Negative (Cancel) + Neutral (Maybe) + Positive (OK/Confirm)
Copied!
Dialog::alert( 'Confirm Action', 'Are you sure you want to delete this item?', ['Cancel', 'Delete']);
#toast()
Displays a brief toast notification message.
Parameters:
string $message
- The message to display
Copied!
Dialog::toast('Item saved successfully!');
Good toast messages
- Short and clear
- Great for confirmations and status updates
- Don't rely on them for critical information
- Avoid showing multiple toasts in quick succession
#share()
Opens the native sharing interface.
Parameters:
string $title
- The share dialog titlestring $text
- Text content to sharestring $url
- URL to share
Copied!
Dialog::share( 'Check this out!', 'I found this amazing Laravel package for mobile development', 'https://nativephp.com');
#Events
#ButtonPressed
Fired when a button is pressed in an alert dialog.
Payload:
int $index
- Index of the pressed button (0-based)string $label
- Label/text of the pressed button
Copied!
use Livewire\Attributes\On;use Native\Mobile\Events\Alert\ButtonPressed; #[On('native:'.ButtonPressed::class)]public function handleAlertButton($index, $label){ switch ($index) { case 0: // First button (usually Cancel) Dialog::toast("You pressed '{$label}'"); break; case 1: // Second button (usually OK/Confirm) $this->performAction(); Dialog::toast("You pressed '{$label}'"); break; }}