Build your first native desktop application with NativePHP in just a few minutes. This guide will walk you through creating a simple “Hello World” desktop app.
In the boot() method, use the Window facade to create and configure your main application window:
app/Providers/NativeAppServiceProvider.php
<?phpnamespace App\Providers;use Native\Desktop\Facades\Window;use Native\Desktop\Facades\Menu;use Native\Desktop\Menu\Menu as MenuBuilder;use Native\Desktop\Menu\Items\MenuItem;class NativeAppServiceProvider{ public function boot(): void { Window::open() ->title('My First Desktop App') ->width(800) ->height(600) ->rememberState(); // Remember window size and position }}
The rememberState() method automatically saves and restores the window’s size and position between sessions.
<?phpnamespace App\Http\Controllers;use Native\Desktop\Facades\Notification;class NotificationController extends Controller{ public function send() { Notification::new() ->title('Hello from NativePHP!') ->message('Your notification was sent successfully.') ->show(); return response()->json(['status' => 'sent']); }}
public function boot(): void{ // Main window Window::open('main') ->title('My First Desktop App') ->width(800) ->height(600) ->rememberState();}
Then open a secondary window from your code:
use Native\Desktop\Facades\Window;// Open a settings windowWindow::open('settings') ->title('Settings') ->url(route('settings')) ->width(600) ->height(400) ->resizable(false);
NativePHP automatically configures a SQLite database for your application:
use Illuminate\Support\Facades\DB;// Create a migrationphp artisan make:migration create_notes_table// Run migrationsphp artisan native:migrate// Use Eloquent as normaluse App\Models\Note;$note = Note::create([ 'title' => 'My First Note', 'content' => 'Hello from NativePHP!',]);
The database is automatically created at database/nativephp.sqlite in development mode. In production, it’s stored in the user’s application data directory.
<?phpnamespace App\Jobs;use Illuminate\Bus\Queueable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Native\Desktop\Facades\Notification;class ProcessData implements ShouldQueue{ use Dispatchable, InteractsWithQueue, Queueable; public function handle(): void { // Do some work sleep(2); // Notify when done Notification::new() ->title('Task Complete') ->message('Your data has been processed.') ->show(); }}
Dispatch the job:
use App\Jobs\ProcessData;ProcessData::dispatch();
Queue workers are automatically started based on your config/nativephp.php configuration:
Running in Development: Your app runs in a browser during development. To test as a true desktop app, you’ll need to build it for your platform.
Hot Reloading: Use Laravel’s built-in development server with hot reloading for the best development experience. Changes to your Blade views and assets will be reflected immediately.