One of the biggest advantages of building desktop apps with NativePHP is having the ability to interact with the user through native system dialogs. Whether itβs a simple alert, a confirmation prompt, or a file picker dialog, NativePHP gives you the tools to integrate these into your Laravel-powered desktop apps β effortlessly.
In this article, we'll walk through how to:
Show basic alerts
Ask for user input via prompts
Use native file dialogs to open or save files
π‘ Why Use Native Dialogs?
Using native dialogs ensures your app feels like it belongs on the user's system β not just a browser pretending to be a desktop app. Native dialogs offer:
Familiarity for the user
System-level access (file pickers, alerts, etc.)
Consistent experience across Windows, macOS, and Linux
π¨ Showing an Alert
To show an alert box with NativePHP, you can use the Dialog facade.
Example:
use Native\Laravel\Facades\Dialog;
Dialog::message('Update Complete', 'Your data has been saved successfully.');
This displays a native system message box with a title and message body.
π§βπ» Prompting for Input
Need user input? Use a prompt dialog:
Dialog::prompt('Enter your name')
->then(function ($value) {
// Do something with the input
logger("User typed: {$value}");
});
The
then()method handles the input from the user asynchronously.
β Confirmation Dialogs
Use a confirmation dialog when you need a yes/no response:
Dialog::confirm('Are you sure you want to exit?')
->then(function (bool $confirmed) {
if ($confirmed) {
// Exit logic
}
});
This is great for destructive actions like deleting data or closing the app.
π Open File Dialog
Want the user to select a file? Use the Dialog::openFile() method.
Dialog::openFile()
->title('Select an image')
->filters([
['name' => 'Images', 'extensions' => ['jpg', 'png', 'gif']],
])
->then(function ($filePath) {
if ($filePath) {
logger("Selected file: {$filePath}");
}
});
πΎ Save File Dialog
To prompt the user for a file location to save something:
Dialog::saveFile()
->title('Save Report')
->defaultPath('report.pdf')
->then(function ($filePath) {
if ($filePath) {
Storage::put($filePath, 'Your report content');
}
});
π§° Other Dialog Options
Method
Description
Dialog::message()
Shows a simple message box
Dialog::prompt()
Prompts user for input
Dialog::confirm()
Displays yes/no confirmation
Dialog::openFile()
Opens file selection dialog
Dialog::openDirectory()
Opens folder selection dialog
Dialog::saveFile()
Prompts user to choose save path
π§ͺ Pro Tip: Combine with Livewire or Vue
You can trigger these dialogs from your UI using Livewire, Vue, or even Inertia. Just trigger a Laravel action, and run the Dialog logic from your controller or Livewire component.
β Wrapping Up
Dialogs are an essential part of any desktop app. NativePHP makes them clean, simple, and native β just like any framework should. With just a few lines of PHP, you can prompt users, alert them, or let them select files.

Top comments (0)