You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NativePHP for Mobile uses [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) to send push notifications to your users.
10
+
11
+
## Setting up your app
12
+
13
+
Once you create a Firebase account and create a project you will be offered to download a `google-services.json` file.
14
+
15
+
This file contains the configuration for your app and is used by the Firebase SDK to retrieve tokens for each device using your app.
16
+
17
+
Simply drag this file into the root of your Laravel project, enable `push_notifications` in the [config](/docs/mobile/1/getting-started/configuration) it will be used automatically.
18
+
19
+
You will see more instructions on how to configure your app in the Firebase documentation, you can ignore all of those, NativePHP handles all of that for you.
20
+
21
+
## Receiving Push Tokens
22
+
23
+
To receive push notifications, you must register a listener for the event. For example,
24
+
take a look at how easy it is to listen for a `TokenGenerated` event in Livewire:
25
+
26
+
```php
27
+
use Livewire\Attributes\On;
28
+
use Livewire\Component;
29
+
use Native\Mobile\Facades\System;
30
+
use Native\Mobile\Events\PushNotification\TokenGenerated;
public function handlePushNotifications(string $token)
41
+
{
42
+
// Do something with the token...
43
+
}
44
+
}
45
+
```
46
+
47
+
Because of the nature of mobile applications you need an api server to handle these tokens. You can use Laravel's built-in `Http` facade to
48
+
`POST` the token to your server, on the server side you need to associate the token with the "user" that owns the device.
49
+
50
+
We **strongly** recommend using [Sanctum](https://laravel.com/docs/12.x/sanctum#main-content) to handle this for you.
51
+
52
+
## The flow
53
+
54
+
Your app authenticates users against your own api server, when users create an account or login the server validates and authenticates the user and passes back a Sanctum token.
55
+
56
+
The token is stored in your apps `session` and is used on subsequent requests to the api server.
57
+
58
+
When a push notification is received, the token is sent to your api server and the server stores it for the user who sent it.
59
+
60
+
> Optionally, you can have a `HasMany` relationship between your users and devices,
61
+
> this allows you to associate a device with a user and then use the device's token
62
+
> to send push notifications to that users devices.
63
+
64
+
## Sending Push Notifications
65
+
66
+
Once you have the token, you may use it from your server-based applications to trigger Push Notifications directly to
67
+
your user's device. We use a package like [google/apiclient](https://github.com/googleapis/google-api-php-client) to send the notifications.
68
+
69
+
This is the exact code used by the NativePHP Kitchen Sink App (available soon on all app stores and GitHub):
70
+
71
+
```php
72
+
Route::group(['middleware' => 'auth:sanctum'], function () {
Copy file name to clipboardExpand all lines: resources/views/docs/mobile/1/getting-started/configuration.md
+47-1Lines changed: 47 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,50 @@ title: Configuration
3
3
order: 200
4
4
---
5
5
6
-
# COMING SOON
6
+
## Overview
7
+
8
+
NativePHP for Mobile is designed so that most configuration happens **inside your Laravel application**, without requiring you to manually open Xcode or Android Studio.
9
+
10
+
After installation, NativePHP sets up the necessary native scaffolding, but your primary interaction remains inside Laravel itself.
11
+
12
+
This page explains the key configuration points you can control directly through Laravel.
13
+
14
+
## The `nativephp.php` Config File
15
+
16
+
The nativephp.php config file is where you can configure the native project for your application.
17
+
18
+
NativePHP uses sensible defaults and makes several assumptions based on default installations for tools required to build and run apps from your computer.
19
+
20
+
You can override these defaults by editing the `nativephp.php` config file in your Laravel project or changing environment variables.
21
+
22
+
```dotenv
23
+
NATIVEPHP_APP_VERSION
24
+
NATIVEPHP_APP_VERSION_CODE
25
+
NATIVEPHP_APP_ID
26
+
NATIVEPHP_DEEPLINK_SCHEME
27
+
NATIVEPHP_DEEPLINK_HOST
28
+
NATIVEPHP_APP_AUTHOR
29
+
NATIVEPHP_GRADLE_PATH
30
+
NATIVEPHP_ANDROID_SDK_LOCATION
31
+
```
32
+
33
+
## Cleanup `env` keys
34
+
35
+
The `cleanup_env_keys` array in the config file allows you to specify keys that should be removed from the `.env` file before bundling.
36
+
This is useful for removing sensitive information like API keys or other secrets.
37
+
38
+
## Cleanup `exclude_files`
39
+
40
+
The `cleanup_exclude_files` array in the config file allows you to specify files and folders that should be removed before bundling.
41
+
This is useful for removing files like logs or other temporary files.
42
+
43
+
## Permissions
44
+
In general, the app stores don't want apps to request permissions that they don't need.
45
+
To enable some permissions your app needs you simply need to change their values in the permissions section.
Copy file name to clipboardExpand all lines: resources/views/docs/mobile/1/getting-started/development.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,5 +3,30 @@ title: Development
3
3
order: 300
4
4
---
5
5
6
-
# COMING SOON
6
+
7
+
## The `nativephp` Directory
8
+
9
+
After running: `php artisan native:install` you’ll see a new `nativephp` directory at the root of your Laravel project as well as a `nativephp.php` config file in your config folder in the Laravel root.
10
+
11
+
This folder contains all the native project files that NativePHP generates for you.
12
+
13
+
You should not need to manually open or edit any native project files under normal circumstances.
14
+
NativePHP handles the heavy lifting for you.
15
+
16
+
## NATIVEPHP_APP_VERSION
17
+
18
+
The NATIVEPHP_APP_VERSION environment variable controls your app's versioning behavior.
19
+
20
+
When building for Android, NativePHP first copies the relevant Laravel files into a temporary directory, zips them, and embeds the archive into the Android project. When the app boots, it checks the embedded version against the previously installed version.
21
+
22
+
If the versions match, the app uses the existing files without re-extracting the archive.
23
+
24
+
If the versions differ — or if the version is set to ***DEBUG*** — the app updates itself by re-extracting the new bundle.
25
+
26
+
This mechanism ensures developers can iterate quickly during development, while providing a faster, more stable experience for end users once an app is published.
27
+
28
+
> Rule of Thumb:
29
+
> During development, keep NATIVEPHP_APP_VERSION set to DEBUG to always refresh the app.
30
+
> When preparing a new release, update it to a semantic version (e.g., 1.2.3) to enable versioned updates for your users.
0 commit comments