Skip to main content

Building a Menu Bar Desktop Application with NativePHP package in Laravel

NativePHP package recently introduced and in Laravel it allows us to design and develop cross platform desktop applications. It has inherited from Electron project. In this blog post I'll show how to come-up with a desktop application using Laravel with Blade templates.

Create a new Laravel Project using composer

composer create-project laravel/laravel laravel-native-php

Installing NativePHP package

composer require nativephp/electron

Run php artisan command in the terminal to check what are the next NativePHP related commands to be executed.

We can see that there is a command to be executed call native:install which will install NativePHP by creating a separate AppServiceProvider for it.

As you can see once executed php artisan native:install command, you'll see it prompts for choosing options for two questions. We just need to select yes for installing the NativePHP NPM dependencies, and select no for starting the NativePHP development server.

After this point everything should looks good, and we can start the Laravel development server using php artisan serve command.

Nice!! We can see a desktop application has appeared as a normal Laravel web application. The difference is you can see the application menu on Mac menu bar as same as other desktop application. With that we can verify this is a desktop application, and not a web application runs on the browser.

Furthermore, it has created a dock icon as well.

Let's customise the code to make it more convenient prior adding some actual business logic to the application.

TIP: Keep in mind that hot reloading already in place, and when you make some changes to the code, it will reflect on the application interface in real time.

Keep the application on top every time

By adding the chain method alwaysOnTop() after calling Window::open() static method, the application will be on top everytime.

Set width, height, minimum height and minimum width


Changing the title

We can change the title by adding the following chain method.

->title('Hey Demo Laravel');

Keep the desktop windows on the same position after hot reload


By calling the above chain method the window keeps at the same position even after the hot reload!!

Furthermore, you can refer to this for a detailed guide.

Happy coding!!


Popular posts from this blog

Deploying a Laravel Application on Laravel Forge with AWS | Step-by-Step Guide

Deploying a Laravel application to the cloud can be a complex and time-consuming process. However, with the help of Laravel Forge and AWS (Amazon Web Services), developers can streamline this deployment process and ensure a smooth transition from development to production. In this article, we will walk you through the steps to deploy a Laravel application from GitHub to AWS using Laravel Forge.   Prerequisites   Before we dive into the deployment process, make sure you have the following prerequisites in place:   A Laravel application hosted on GitHub. An AWS account with proper IAM permissions to create and manage resources like EC2 instances, databases, and S3 buckets. A Laravel Forge account. Step 1: Set Up Laravel Forge   Sign in to your Laravel Forge account or create a new one if you haven't already done so.   Once logged in, click on the "Connect to a Server" button and follow the instructions to add your AWS account. This process will allow Laravel Forge to manage

Microsoft's AZ-900: Empowering the Cloud Journey with Azure Fundamentals

In today's digitally-driven world, the cloud has become the backbone of modern technology, powering countless businesses and organizations across the globe. Microsoft, a pioneer in the tech industry, recognized the growing importance of cloud computing early on and has developed a comprehensive certification program to equip individuals with the necessary knowledge to harness the power of the cloud. The Exam AZ-900: Microsoft Azure Fundamentals is the gateway to understanding and leveraging the potential of Microsoft Azure. Even more enticingly, Microsoft offers this certification along with free training, making it accessible to anyone aspiring to thrive in the cloud ecosystem. Unlocking the Potential of Azure with AZ-900 The Microsoft Azure Fundamentals (AZ-900) exam is designed for individuals who are new to the cloud domain or those looking to validate their fundamental knowledge of cloud concepts. The exam covers foundational topics, such as cloud computing concepts, core Azur