### List Installed NativePHP Plugins Source: https://nativephp.com/docs/mobile/3/plugins/using-plugins Verifies the installation of NativePHP plugins by listing them and their provided features using the `native:plugin:list` Artisan command. ```shell php artisan native:plugin:list ``` -------------------------------- ### Install a NativePHP Plugin Source: https://nativephp.com/docs/mobile/3/plugins/using-plugins Installs a NativePHP plugin as a standard Composer package. The plugin's service provider is auto-discovered by Laravel. ```shell composer require vendor/nativephp-plugin-name ``` -------------------------------- ### Example: Download and Copy ML Model - PHP Source: https://nativephp.com/docs/mobile/3/plugins/lifecycle-hooks This example demonstrates a `copy_assets` hook that downloads an ML model if it's not locally cached and then copies it to the appropriate platform-specific asset or bundle location. It utilizes helper methods like `pluginPath()`, `downloadIfMissing()`, `isAndroid()`, `isIos()`, `copyToAndroidAssets()`, and `copyToIosBundle()`. ```php public function handle(): int { $modelPath = $this->pluginPath() . '/resources/models/model.tflite'; // Download if not cached locally $this->downloadIfMissing( 'https://example.com/models/v2/model.tflite', $modelPath ); // Copy to the appropriate platform location if ($this->isAndroid()) { $this->copyToAndroidAssets('models/model.tflite', 'models/model.tflite'); $this->info('Model copied to Android assets'); } if ($this->isIos()) { $this->copyToIosBundle('models/model.tflite', 'models/model.tflite'); $this->info('Model copied to iOS bundle'); } return self::SUCCESS; } ``` -------------------------------- ### List Registered Plugins (Shell) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins View a list of all plugins currently registered with your application. Use the `--all` flag to see all installed plugins, including those that are not yet registered. ```shell # Show registered plugins php artisan native:plugin:list # Show all installed plugins (including unregistered) php artisan native:plugin:list --all ``` -------------------------------- ### Install NativePHP Development Agents Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Installs specialized AI agents for NativePHP plugin development. These agents assist with various aspects of native development, including Android/Kotlin, iOS/Swift, JavaScript bridge integration, and plugin scaffolding. Use flags like `--all` to install all agents or `--force` to overwrite existing files. ```shell php artisan native:plugin:install-agent ``` -------------------------------- ### Rebuild NativePHP App with Plugins Source: https://nativephp.com/docs/mobile/3/plugins/using-plugins Rebuilds the NativePHP application to compile the native code of installed plugins using the `native:run` command. ```shell php artisan native:run ``` -------------------------------- ### Fake Shell Interaction Test - PHP Source: https://nativephp.com/docs/desktop/2/testing/shell This example demonstrates how to fake shell interactions within a PHPUnit test case using NativePHP's Shell facade. It shows how to set up the fake shell, trigger an action, and assert that an external URL was opened. ```php use Native\Desktop\Facades\Shell; #[PHPUnit\Framework\Attributes\Test] public function example(): void { Shell::fake(); $this->get('/whatever-action'); Shell::assertOpenedExternal('https://some-url.test'); } ``` -------------------------------- ### Create Boost Guidelines for NativePHP Plugins Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Generates AI guidelines for NativePHP plugins when using Laravel Boost. This command creates a `core.blade.php` file that documents the plugin's facade, methods, events, and JavaScript usage, enabling AI assistants to understand and utilize the plugin effectively upon installation. ```shell php artisan native:plugin:boost ``` -------------------------------- ### Force Native Project Reinstall (Shell) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins When making significant changes to native code or the plugin's manifest, force a fresh install of the native projects. This ensures that the native projects are rebuilt from scratch, incorporating all the latest changes. ```shell php artisan native:install --force ``` -------------------------------- ### JavaScript Bridge Call Example (JavaScript) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Example of a JavaScript function that communicates with the native backend via a bridge. It defines a base URL for API calls and a generic `bridgeCall` function to handle POST requests with method and parameters. ```javascript // resources/js/myPlugin.js const baseUrl = '/_native/api/call'; async function bridgeCall(method, params = {}) { const response = await fetch(baseUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ method, params }) }); return response.json(); } export async function doSomething(options = {}) { return bridgeCall('MyPlugin.DoSomething', options); } ``` -------------------------------- ### Require Plugin with Composer (Shell) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins After adding the plugin as a path repository, use Composer to require the plugin into your project. This command installs the plugin and makes it available for use in your application. ```shell composer require vendor/my-plugin ``` -------------------------------- ### Scaffold a New NativePHP Plugin Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Use the `native:plugin:create` Artisan command to interactively scaffold a new NativePHP plugin. This command guides you through naming, namespace selection, and feature options, generating a complete plugin structure. ```shell php artisan native:plugin:create ``` -------------------------------- ### Complete NativePHP Plugin Manifest Example (Firebase ML Kit) Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration This comprehensive JSON manifest outlines a NativePHP plugin integrating Firebase ML Kit. It includes configurations for namespace, bridge functions, events, Android-specific settings (permissions, features, dependencies, activities, meta-data), iOS-specific settings (info.plist, dependencies, background modes, entitlements), assets, secrets, and pre-compile hooks. ```json { "namespace": "FirebaseML", "bridge_functions": [ { "name": "FirebaseML.Analyze", "android": "com.nativephp.plugins.firebaseml.AnalyzeFunctions.Analyze", "ios": "FirebaseMLFunctions.Analyze" } ], "events": [ "Vendor\FirebaseML\Events\AnalysisComplete" ], "android": { "permissions": [ "android.permission.CAMERA", "android.permission.INTERNET" ], "features": [ {"name": "android.hardware.camera", "required": true} ], "dependencies": { "implementation": [ "com.google.firebase:firebase-ml-vision:24.1.0", "com.google.firebase:firebase-core:21.1.1" ] }, "activities": [ { "name": ".CameraPreviewActivity", "theme": "@style/Theme.AppCompat.Light.NoActionBar", "exported": false, "configChanges": "orientation|screenSize|keyboardHidden" } ], "meta_data": [ { "name": "com.google.firebase.ml.vision.DEPENDENCIES", "value": "ocr" } ] }, "ios": { "info_plist": { "NSCameraUsageDescription": "Camera is used for ML analysis" }, "dependencies": { "pods": [ {"name": "Firebase/MLVision", "version": "~> 10.0"}, {"name": "Firebase/Core", "version": "~> 10.0"} ] }, "background_modes": ["processing"], "entitlements": { "com.apple.developer.associated-domains": ["applinks:example.com"] } }, "assets": { "android": { "google-services.json": "google-services.json" }, "ios": { "GoogleService-Info.plist": "Resources/GoogleService-Info.plist" } }, "secrets": { "FIREBASE_API_KEY": { "description": "Firebase API key from Firebase Console", "required": true } }, "hooks": { "pre_compile": "nativephp:firebase-ml:setup" } } ``` -------------------------------- ### Handle Missing Required Props Error in EDGE Components Source: https://nativephp.com/docs/mobile/3/edge-components This example illustrates the error message generated by EDGE when a required prop is missing for a native component, specifically `native:bottom-nav-item`. It highlights the validation process that occurs at render time, providing clear instructions on how to correct the configuration by adding the missing attributes. ```text EDGE Component is missing required properties: 'label'. Add these attributes to your component: label="..." EDGE Component is missing required properties: 'label'. Add these attributes to your component: label="..." ``` -------------------------------- ### Configure Initialization Functions for NativePHP Plugins Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Plugins can define native functions to be called during application startup for early SDK setup. This JSON configuration specifies the initialization function for Android and iOS platforms, ensuring that necessary SDKs are ready before any bridge functions are invoked. ```json { "android": { "init_function": "com.myvendor.plugins.myplugin.MyPluginInit.initialize" }, "ios": { "init_function": "MyPluginInit.initialize" } } ``` -------------------------------- ### Android Package Declaration for Kotlin Bridge Functions Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Declare a package at the top of each Kotlin file for Android bridge functions to ensure correct file placement. This avoids conflicts by using a vendor-namespaced package. Example shows a `DoSomething` bridge function. ```kotlin // resources/android/src/MyPluginFunctions.kt package com.myvendor.plugins.myplugin import com.nativephp.mobile.bridge.BridgeFunction import com.nativephp.mobile.bridge.BridgeResponse object MyPluginFunctions { class DoSomething : BridgeFunction { override fun execute(parameters: Map): Map { return BridgeResponse.success(mapOf("status" to "done")) } } } ``` -------------------------------- ### Handle Token Generated Event (PHP) Source: https://nativephp.com/docs/mobile/3/concepts/push-notifications Listens for the `TokenGenerated` event, which fires when a push notification token is successfully obtained. This example demonstrates storing the token using a hypothetical APIService. Requires the `OnNative` attribute. ```php use App\Services\APIService; use Native\Mobile\Attributes\OnNative; use Native\Mobile\Facades\PushNotifications; use Native\Mobile\Events\PushNotification\TokenGenerated; class PushNotifications extends Component { #[OnNative(TokenGenerated::class)] public function storePushToken(APIService $api, string $token) { $api->storePushToken($token); } } ``` -------------------------------- ### Generate Hook Command - Shell Source: https://nativephp.com/docs/mobile/3/plugins/lifecycle-hooks Use the NativePHP scaffolding tool to generate a new hook command for your plugin. This command will guide you through selecting the plugin and the specific hooks to create, automating the generation of the command class, manifest updates, and service provider registration. ```shell php artisan native:plugin:make-hook ``` -------------------------------- ### Fake Child Process Assertions in PHP Source: https://nativephp.com/docs/desktop/2/testing/child-process This snippet demonstrates how to fake child process interactions in PHP for testing purposes. It utilizes the `ChildProcess::fake()` method to mock child process calls and then uses assertion methods like `assertGet` and `assertMessage` to verify that the expected child processes were invoked with the correct payloads. This is useful for ensuring your application correctly communicates with background workers without actually starting them. ```php use Native\Desktop\Facades\ChildProcess; #[PHPUnit\Framework\Attributes\Test] public function example(): void { ChildProcess::fake(); $this->get('/whatever-action'); ChildProcess::assertGet('background-worker'); ChildProcess::assertMessage(fn (string $message, string|null $alias) => $message === '{"some-payload":"for-the-worker"}' && $alias === null); } ``` -------------------------------- ### PHP Advanced Window Instance Assertions with Mockery Source: https://nativephp.com/docs/desktop/2/testing/windows This PHP code demonstrates advanced testing in NativePHP by faking the Window facade and using Mockery to assert specific method calls on a mocked window instance. It shows how to chain methods like route, transparent, height, width, minHeight, and minWidth. ```php use Illuminate\Support\Facades\Http; use Native\Desktop\Facades\Window; use Native\Desktop\Windows\Window as WindowImplementation; use Mockery; #[PHPUnit\Framework\Attributes\Test] public function example(): void { Http::fake(); Window::fake(); Window::alwaysReturnWindows([ $mockWindow = Mockery::mock(WindowImplementation::class)->makePartial(), ]); $mockWindow->shouldReceive('route')->once()->with('action')->andReturnSelf(); $mockWindow->shouldReceive('transparent')->once()->andReturnSelf(); $mockWindow->shouldReceive('height')->once()->with(500)->andReturnSelf(); $mockWindow->shouldReceive('width')->once()->with(775)->andReturnSelf(); $mockWindow->shouldReceive('minHeight')->once()->with(500)->andReturnSelf(); $mockWindow->shouldReceive('minWidth')->once()->with(775)->andReturnSelf(); $this->get(route('action')); } ``` -------------------------------- ### Mocking Desktop Window with PHPUnit Source: https://nativephp.com/docs/desktop/2/testing/basics This snippet demonstrates how to use `Window::fake()` to mock desktop window interactions within a PHPUnit test. It replaces the real window behavior with a fake one, allowing you to assert window states like being opened without needing the actual Electron application running. This is useful for isolating your application logic during testing. ```php use Native\Desktop\Facades\Window; #[\PHPUnit\Framework\Attributes\Test] public function example(): void { Window::fake(); $this->get('/whatever-action'); Window::assertOpened('window-name'); } ``` -------------------------------- ### Use Plugin Features via Facade Source: https://nativephp.com/docs/mobile/3/plugins/using-plugins Demonstrates how to interact with native functionality provided by a plugin using its dedicated facade in PHP. ```php use Vendor\PluginName\Facades\PluginName; // Call a native function $result = PluginName::doSomething(['option' => 'value']); ``` -------------------------------- ### iOS CocoaPods Dependencies Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Specifies iOS dependencies to be managed by CocoaPods. These are defined in the `pods` array under `ios.dependencies`, with each entry including the pod `name` and an optional `version` constraint. NativePHP generates a `Podfile` and runs `pod install`. ```json { "ios": { "dependencies": { "pods": [ {"name": "GoogleMLKit/FaceDetection", "version": "~> 4.0"}, {"name": "TensorFlowLiteSwift", "version": "~> 2.13"} ] } } } ``` -------------------------------- ### Fake Power Monitor Test Case - PHP Source: https://nativephp.com/docs/desktop/2/testing/power-monitor This snippet demonstrates how to fake the Power Monitor in a PHPUnit test case. It shows how to initialize the fake, perform an action, and then assert the expected behavior of the Power Monitor. This is useful for testing components that interact with system power states without relying on the actual system behavior. ```php use Native\Desktop\Facades\PowerMonitor; #[\PHPUnit\Framework\Attributes\Test] public function example(): void { PowerMonitor::fake(); $this->get('/whatever-action'); PowerMonitor::assertGetSystemIdleState('...'); } ``` -------------------------------- ### Publish NativePHP Service Provider (Shell) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Publish the NativeServiceProvider to your application. This command copies the service provider file to the correct location, allowing you to register plugins. ```shell php artisan vendor:publish --tag=nativephp-plugins-provider ``` -------------------------------- ### Register a Plugin (Shell) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Register a plugin with your application using the provided Artisan command. This command automatically adds the plugin's service provider to the `plugins()` array in your `NativeServiceProvider.php`. ```shell php artisan native:plugin:register vendor/plugin-name ``` -------------------------------- ### Listen to Plugin Events with #[OnNative] Source: https://nativephp.com/docs/mobile/3/plugins/using-plugins Shows how to listen for events dispatched by NativePHP plugins within Livewire components using the `#[OnNative]` attribute. ```php use Native\Mobile\Attributes\OnNative; use Vendor\PluginName\Events\SomethingCompleted; #[OnNative(SomethingCompleted::class)] public function handleCompletion($result) { // React to the event } ``` -------------------------------- ### Configure Associated Domain for NativePHP App Source: https://nativephp.com/docs/mobile/3/concepts/deep-links Allows real HTTPS URLs to open your NativePHP app instead of a web browser if the app is installed. This enhances app discovery and user experience. Configure your domain in the .env file and host verification files on your server. ```dotenv NATIVEPHP_DEEPLINK_HOST=example.net ``` -------------------------------- ### PHP Unit Test Window Assertions Source: https://nativephp.com/docs/desktop/2/testing/windows This PHP code snippet demonstrates how to use NativePHP's Window facade for faking and asserting window states within a PHPUnit test. It covers asserting if a window was opened, closed, or hidden, and utilizes HTTP faking for related requests. ```php use Native\Desktop\Facades\Window; use Illuminate\Support\Facades\Http; #[PHPUnit\Framework\Attributes\Test] public function example(): void { Http::fake(); Window::fake(); $this->get('/whatever-action'); Window::assertOpened(fn (string $windowId) => Str::startsWith($windowId, ['window-name'])); Window::assertClosed('window-name'); Window::assertHidden('window-name'); } ``` -------------------------------- ### Fake Global Shortcut Assertions in PHP Source: https://nativephp.com/docs/desktop/2/testing/global-shortcut This PHP code snippet demonstrates how to use the `GlobalShortcut::fake()` method to test global shortcut registrations and events. It utilizes assertions like `assertKey`, `assertRegisteredCount`, and `assertEvent` to verify shortcut behavior without actual system-level registration. ```php use Native\Desktop\Facades\GlobalShortcut; #[PHPUnit\Framework\Attributes\Test] public function example(): void { GlobalShortcut::fake(); $this->get('/whatever-action'); GlobalShortcut::assertKey('CmdOrCtrl+,'); GlobalShortcut::assertRegisteredCount(1); GlobalShortcut::assertEvent(OpenPreferencesEvent::class); } ``` -------------------------------- ### Declare Secrets and Environment Variables for NativePHP Plugins Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Define required environment variables and secrets for your NativePHP plugin. This ensures sensitive information like API keys is handled securely and validated during the build process. Secrets can be marked as required or optional, with descriptions guiding users on how to obtain the necessary values. ```json { "secrets": { "MAPBOX_DOWNLOADS_TOKEN": { "description": "Mapbox SDK download token from mapbox.com/account/access-tokens", "required": true }, "FIREBASE_API_KEY": { "description": "Firebase project API key", "required": false } } } ``` -------------------------------- ### Calling Native Functions and Handling Events in PHP Source: https://nativephp.com/docs/mobile/3/plugins/introduction This snippet demonstrates how to interact with native functionalities provided by a NativePHP plugin. It shows calling a native method via a facade and listening for events dispatched from native code to Livewire components. ```php use Vendor\MyPlugin\Facades\MyPlugin; // Call native functions MyPlugin::doSomething(); // Listen for events #[OnNative(MyPlugin\Events\SomethingHappened::class)] public function handleResult($data) { // Handle it } ``` -------------------------------- ### Placeholder Substitution in Text Assets Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Supports placeholder substitution for text-based assets like XML, JSON, and plist files. Environment variables enclosed in `${ENV_VAR}` are replaced with their actual values during the build process. ```xml ${MY_PLUGIN_API_KEY} ``` -------------------------------- ### iOS Info.plist Configuration Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Configures iOS-specific settings for the `Info.plist` file, including permission usage descriptions and API keys. These are provided as key-value pairs under `ios.info_plist` and are merged into the app's `Info.plist`. Environment variable placeholders can be used for sensitive values. ```json { "ios": { "info_plist": { "NSCameraUsageDescription": "This app uses the camera for scanning", "NSMicrophoneUsageDescription": "This app records audio for transcription", "NSLocationWhenInUseUsageDescription": "This app needs your location", "MBXAccessToken": "${MAPBOX_ACCESS_TOKEN}" } } } ``` -------------------------------- ### Register a NativePHP Plugin Source: https://nativephp.com/docs/mobile/3/plugins/using-plugins Registers a NativePHP plugin to include its native code in builds. This involves publishing the NativeServiceProvider and then using the `native:plugin:register` Artisan command. ```shell php artisan vendor:publish --tag=nativephp-plugins-provider php artisan native:plugin:register vendor/nativephp-plugin-name ``` -------------------------------- ### Platform Configuration Structure Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Defines the overall structure for platform-specific settings in the manifest, grouping configurations for Android and iOS under their respective keys. This includes permissions, dependencies, repositories, activities, and services for Android, and info_plist and dependencies for iOS. ```json { "android": { "permissions": [...], "dependencies": {...}, "repositories": [...], "activities": [...], "services": [...] }, "ios": { "info_plist": {...}, "dependencies": {...} } } ``` -------------------------------- ### Add Plugin Service Provider to NativeServiceProvider (PHP) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Manually add the plugin's service provider class to the `plugins()` array in your `app/Providers/NativeServiceProvider.php` file. This ensures the plugin is recognized and compiled into your native builds. ```php public function plugins(): array { return [ \Vendor\PluginName\PluginNameServiceProvider::class, ]; } ``` -------------------------------- ### Copy Static Assets to Native Projects Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Declare static files to be copied to native projects using the 'assets' field. This simplifies basic file copying compared to writing custom hooks. The format is 'source': 'destination', where 'source' is relative to the plugin's resources directory and 'destination' is the target path in the native project. ```json { "assets": { "android": { "models/detector.tflite": "assets/ml/detector.tflite", "config/settings.xml": "res/raw/plugin_settings.xml" }, "ios": { "models/detector.mlmodel": "Resources/ml/detector.mlmodel", "config/settings.plist": "Resources/plugin_settings.plist" } } } ``` -------------------------------- ### Configure Android Meta-Data for SDKs Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Add application-level meta-data elements for SDK configuration, such as API keys or notification icons. Each entry requires a 'name' for the meta-data key and a 'value', which can include environment variable placeholders. ```json { "android": { "meta_data": [ { "name": "com.google.android.geo.API_KEY", "value": "${GOOGLE_MAPS_API_KEY}" }, { "name": "com.google.firebase.messaging.default_notification_icon", "value": "@drawable/ic_notification" } ] } } ``` -------------------------------- ### Specify Minimum Platform Versions for Plugins Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Define the minimum platform versions required by your plugin for both Android and iOS. This ensures compatibility and warns users if their app targets a lower version than your plugin necessitates. Android versions are integers (SDK version), while iOS versions are strings. ```json { "android": { "min_version": 33 }, "ios": { "min_version": "18.0" } } ``` -------------------------------- ### Android Permissions Configuration Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Specifies Android permissions required by the application. These are listed as strings under the `android.permissions` key and are added to the app's `AndroidManifest.xml` during the build process. A link to the Android Manifest.permission reference is provided for a complete list. ```json { "android": { "permissions": [ "android.permission.CAMERA", "android.permission.RECORD_AUDIO", "android.permission.ACCESS_FINE_LOCATION" ] } } ``` -------------------------------- ### Add Plugin as Local Path Repository (JSON) Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Configure your application's composer.json to include your plugin as a local path repository during development. This allows Composer to manage your plugin as a dependency without publishing it to a package registry. ```json { "repositories": [ {"type": "path", "url": "../packages/my-plugin"} ] } ``` -------------------------------- ### Tail NativePHP Application Logs Source: https://nativephp.com/docs/mobile/3/plugins/validation-testing Use this command to stream the logs from your NativePHP application in real-time. This is invaluable for debugging native code execution and tracing the flow of your plugin's functionality by checking console output and device logs. ```shell php artisan native:tail ``` -------------------------------- ### Integrate Inertia with NativePHP Navigation Links Source: https://nativephp.com/docs/mobile/3/edge-components This JavaScript snippet shows how to integrate Inertia.js with NativePHP's EDGE components to handle navigation requests. By adding the Inertia router to the window object, links within EDGE components can be transformed into Inertia `` components, enabling client-side routing instead of full page reloads. ```javascript import { router } from '@inertiajs/vue3';   declare global { interface Window { router: typeof router; } }   window.router = router; import { router } from '@inertiajs/vue3'; declare global { interface Window { router: typeof router; } } window.router = router; ``` -------------------------------- ### Test PHP Facades and Event Handling with PHPUnit Source: https://nativephp.com/docs/mobile/3/plugins/validation-testing Write standard PHPUnit tests to verify your plugin's PHP components, such as facades and event handling logic. This allows you to ensure that your PHP code behaves as expected within the Laravel framework context. ```php public function test_plugin_facade_is_accessible() { $this->assertInstanceOf(MyPlugin::class, app(MyPlugin::class)); } ``` -------------------------------- ### Composer.json Configuration for NativePHP Plugins Source: https://nativephp.com/docs/mobile/3/plugins/creating-plugins Configure your `composer.json` file to specify the plugin type as `nativephp-plugin`. This also includes Laravel service provider registration and the path to the NativePHP manifest file. ```json { "name": "vendor/my-plugin", "type": "nativephp-plugin", "extra": { "laravel": { "providers": ["Vendor\\MyPlugin\\MyPluginServiceProvider"] }, "nativephp": { "manifest": "nativephp.json" } } } ``` -------------------------------- ### Create Seed Migration - Artisan CLI Source: https://nativephp.com/docs/mobile/3/concepts/databases This command generates a new migration file specifically for seeding application data. It utilizes the Artisan command-line interface provided by Laravel. ```shell php artisan make:migration seed_app_settings ``` -------------------------------- ### iOS Swift Package Manager Dependencies Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Configures iOS dependencies using Swift Package Manager. These are listed in the `swift_packages` array under `ios.dependencies`, with each entry specifying the package `url` and `version`. Swift Packages are preferred over CocoaPods when available. ```json { "ios": { "dependencies": { "swift_packages": [ { "url": "https://github.com/example/SomePackage", "version": "1.0.0" } ] } } } ``` -------------------------------- ### ML Maps Plugin Manifest (JSON) Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies This JSON manifest defines the configuration for an ML Maps plugin. It specifies the plugin's name, namespace, and platform-specific settings for Android and iOS, including permissions, dependencies, and API keys. It also outlines the required secrets for Mapbox integration. ```json { "name": "vendor/ml-maps-plugin", "namespace": "MLMaps", "android": { "permissions": [ "android.permission.CAMERA", "android.permission.ACCESS_FINE_LOCATION" ], "dependencies": { "implementation": [ "com.google.mlkit:object-detection:17.0.0", "com.mapbox.maps:android:11.0.0" ] }, "repositories": [ { "url": "https://api.mapbox.com/downloads/v2/releases/maven", "credentials": { "username": "mapbox", "password": "${MAPBOX_DOWNLOADS_TOKEN}" } } ] }, "ios": { "info_plist": { "NSCameraUsageDescription": "Camera is used for real-time object detection", "NSLocationWhenInUseUsageDescription": "Location is used to display your position on the map", "MBXAccessToken": "${MAPBOX_PUBLIC_TOKEN}" }, "dependencies": { "pods": [ {"name": "MapboxMaps", "version": "~> 11.0"} ] } }, "secrets": { "MAPBOX_DOWNLOADS_TOKEN": { "description": "Mapbox SDK download token from mapbox.com/account/access-tokens", "required": true }, "MAPBOX_PUBLIC_TOKEN": { "description": "Mapbox public access token for runtime API calls", "required": true } } } ``` -------------------------------- ### Enable iOS Background Execution Modes Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Enable background execution capabilities for iOS applications by specifying modes in the 'background_modes' array. These values are added to the 'UIBackgroundModes' in the 'Info.plist' file, allowing for tasks like audio playback, background fetch, or location updates. ```json { "ios": { "background_modes": ["audio", "fetch", "processing", "location"] } } ``` -------------------------------- ### Configure OAuth Redirect URI with NativePHP Browser Facade Source: https://nativephp.com/docs/mobile/3/concepts/authentication This snippet demonstrates how to configure the redirect URI for OAuth authentication using the `Native\Mobile\Facades\Browser::auth()` method. It requires setting a deep link scheme in your `.env` file and specifying the full redirect URL, including your custom scheme and callback route. ```dotenv NATIVEPHP_DEEPLINK_SCHEME=myapp ``` ```php use Native\Mobile\Facades\Browser; Browser::auth('https://workos.com/my-company/auth?redirect=myapp://auth/handle'); ``` -------------------------------- ### Android Custom Repository Configuration Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Adds custom Maven repositories for Android dependencies, such as private or non-standard repositories. These are configured under `android.repositories` with a `url` and optional `credentials` for authentication. These are added to the app's `settings.gradle.kts`. ```json { "android": { "repositories": [ { "url": "https://api.mapbox.com/downloads/v2/releases/maven", "credentials": { "username": "mapbox", "password": "${MAPBOX_DOWNLOADS_TOKEN}" } } ] } } ``` -------------------------------- ### Fake Queue Worker Test Case - PHP Source: https://nativephp.com/docs/desktop/2/testing/queue-worker This PHP code snippet demonstrates how to fake the Queue Worker for testing purposes. It uses `QueueWorker::fake()` to mock the worker and `QueueWorker::assertUp()` to verify its state with custom configuration. ```php use Native\Desktop\Facades\QueueWorker; use Native\Desktop\DTOs\QueueConfig; #[PHPUnit\Framework\Attributes\Test] public function example(): void { QueueWorker::fake(); $this->get('/whatever-action'); QueueWorker::assertUp(fn (QueueConfig $config) => $config->alias === 'custom'); } ``` -------------------------------- ### Seed Application Data - PHP Migration Source: https://nativephp.com/docs/mobile/3/concepts/databases This PHP code snippet demonstrates how to insert initial data into the 'categories' table within a migration. It uses Laravel's DB facade for database operations. ```php use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; return new class extends Migration { public function up() { DB::table('categories')->insert([ ['name' => 'Work', 'color' => '#3B82F6'], ['name' => 'Personal', 'color' => '#10B981'], ]); } }; ``` -------------------------------- ### Declare iOS Capabilities for Xcode Configuration Source: https://nativephp.com/docs/mobile/3/plugins/advanced-configuration Declare specific iOS capabilities that your plugin requires. These are distinct from entitlements and are used for configuring the Xcode project settings, such as enabling push notifications or background modes. ```json { "ios": { "capabilities": ["push-notifications", "background-modes", "healthkit"] } } ``` -------------------------------- ### Android Gradle Dependencies Source: https://nativephp.com/docs/mobile/3/plugins/permissions-dependencies Defines Android dependencies using Gradle. These are added under `android.dependencies` and specified by dependency type (e.g., `implementation`, `api`). These are added to the app's `build.gradle.kts` during compilation. ```json { "android": { "dependencies": { "implementation": [ "com.google.mlkit:face-detection:16.1.5", "org.tensorflow:tensorflow-lite:2.13.0" ] } } } ```