use Native\Desktop\Facades\Dialog;$filePath = Dialog::new() ->title('Select a file') ->open();if ($filePath) { // User selected a file $contents = file_get_contents($filePath);}
On macOS, display the dialog as a sheet attached to a window:
use Native\Desktop\Facades\Window;$file = Dialog::new() ->asSheet() // Attaches to current window ->open();// Or attach to a specific window$file = Dialog::new() ->asSheet($windowId) ->open();
Sheet dialogs are modal to the window they’re attached to, while standalone dialogs are modal to the entire application.
use Native\Desktop\Facades\Dialog;class ImageImporter{ public function importImages() { $images = Dialog::new() ->title('Select Images to Import') ->filter('Images', ['jpg', 'jpeg', 'png', 'gif', 'webp']) ->multiple() ->defaultPath(storage_path('imports')) ->open(); if (empty($images)) { return; } foreach ($images as $imagePath) { $this->processImage($imagePath); } } protected function processImage($path) { // Process the image }}
Dialog methods return null if the user cancels the dialog. Always check the return value before proceeding.