Setting Up Your First NativePHP Project in Laravel
 Rahul Gupta

Rahul Gupta @therahul_gupta

About: I am Software Engineer

Joined:
Jun 5, 2022

Setting Up Your First NativePHP Project in Laravel

Publish Date: May 31
2 0

Setting Up Your First NativePHP Project in Laravel

In our last post, we introduced you to NativePHP, a powerful tool that lets you build native desktop applications using Laravel. Today, we’re getting our hands dirty and setting up our very first NativePHP app—from scratch.

Let’s bring Laravel from the browser to the desktop.


🧰 Prerequisites

Before we begin, make sure you have the following tools installed on your machine:

  • PHP 8.1+

  • Composer

  • Node.js & NPM

  • Laravel (v10 or above recommended)

  • Git

  • Electron Builder (will be handled via NativePHP)

You can check versions with:

php -v
composer -V
node -v
npm -v
Enter fullscreen mode Exit fullscreen mode

🧱 Step 1: Create a New Laravel Project

If you don’t already have a Laravel project, let’s create one:

composer create-project laravel/laravel nativephp-demo
cd nativephp-demo
Enter fullscreen mode Exit fullscreen mode

Or you can use an existing Laravel app.


📦 Step 2: Install NativePHP

Now, install the NativePHP Electron package:

composer require nativephp/electron
Enter fullscreen mode Exit fullscreen mode

After installation, you’ll have access to Artisan commands specific to NativePHP.


⚙️ Step 3: Install NativePHP Core Files

Run the following command to scaffold NativePHP-specific files:

php artisan native:install
Enter fullscreen mode Exit fullscreen mode

This will publish:

  • native.php config file

  • Native-specific entry points and logic

  • Electron support structure

You’ll also notice a new file at app/NativePHP/MainWindow.php—this is where you can customize your app’s native window.


🧪 Step 4: Run Your Native App

To test your desktop app:

php artisan native:serve
Enter fullscreen mode Exit fullscreen mode

This will:

  • Spin up your Laravel app locally

  • Launch an Electron window that renders your Laravel app

  • Open a native desktop window displaying your Laravel view

🎉 Boom! You now have a working Laravel-powered desktop app!


🪟 What’s Going On Under the Hood?

NativePHP:

  • Spins up a local server (typically 127.0.0.1:8000)

  • Wraps that in an Electron shell

  • Uses your default Blade views (or Vue/React SPA if set up)

You can customize the window by editing app/NativePHP/MainWindow.php:

use Native\Laravel\Facades\Window;

public function boot()
{
    Window::open()
        ->title('My First NativePHP App')
        ->width(1024)
        ->height(768);
}
Enter fullscreen mode Exit fullscreen mode

🖼️ Optional: Add a Blade View

Create a basic homepage:

php artisan make:controller HomeController


// app/Http/Controllers/HomeController.php
public function index()
{
    return view('welcome');
}
Enter fullscreen mode Exit fullscreen mode

Update routes/web.php:

Route::get('/', [HomeController::class, 'index']);
Enter fullscreen mode Exit fullscreen mode

🔚 Wrapping Up

You’ve just created your first desktop application with Laravel using NativePHP!


📁 Files Summary

  • Laravel project root

  • composer.json with nativephp/electron

  • app/NativePHP/MainWindow.php

  • Native app served on Electron window


🧩 NativePHP Commands Cheat Sheet

Command

Description

php artisan native:install

Setup NativePHP structure

php artisan native:serve

Serve Laravel as desktop app

php artisan native:build

Package for production


🔗 Useful Links


🧠 Pro Tip: Treat this as a Laravel project first. You get all the Laravel goodies—routes, models, jobs, and queues—running on the desktop.

Comments 0 total

    Add comment