NativePHP Documentation

repository·main·Indexed 43 days ago

https://github.com/nativephp/nativephp.com

Documentation for NativePHP, a framework for building native desktop applications with PHP and Laravel. Includes guides on broadcasting custom events, managing background tasks via the ChildProcess facade, utilizing SQLite for local databases, and configuring the Admin MCP (Model Context Protocol) for administrative functions.

Tokens
241.3K
Snippets
857
Records
1.2K
Agent score
53%

What's inside NativePHP

  1. Introduction to NativePHP for Mobile

    main

    NativePHP for Mobile allows you to run full PHP applications natively on iOS and Android devices without requiring a web server. It works by embedding a statically compiled PHP runtime alongside your Laravel application and bridging it to native platform APIs.

    Key Features

    • No Web Server Required: The application runs entirely on-device and is capable of offline-first operation.
    • Cross-Platform: Build for both iOS and Android from a single PHP codebase.
    • Native Performance: Uses an embedded PHP runtime optimized for each mobile platform.
    • Laravel Ecosystem: Leverages existing Laravel skills and tools.

    How it Works

    1. A statically-compiled PHP runtime is bundled into a Swift (iOS) or Kotlin (Android) shell application.
    2. Custom Swift/Kotlin bridges manage the PHP environment and execute your code.
    3. A custom PHP extension exposes native functions as PHP interfaces.
    4. The UI is rendered in a native web view, allowing you to use your existing web development workflows.
  2. What is NativePHP for Mobile?

    main

    NativePHP for Mobile is a library that allows you to run full PHP applications natively on iOS and Android devices without requiring a web server. It works by embedding a pre-compiled PHP runtime alongside Laravel and bridging directly into platform-specific native APIs.

    Key features include:

    • Native Performance: Runs via an embedded PHP runtime optimized for each platform.
    • True Native APIs: Access hardware like camera, biometrics, and push notifications via PHP.
    • Laravel Powered: Uses the existing Laravel ecosystem.
    • Offline-First: The app runs entirely on-device with no web server required.
    • Cross-Platform: Single codebase for both iOS and Android.
  3. Use the File API to manage device files

    main

    The File API provides utilities for moving and copying files on a mobile device. Operations are synchronous and require absolute paths.

    Important Requirements:

    • Use absolute paths (e.g., via Laravel's storage_path() helper).
    • The source file must exist.
    • The destination directory must exist.
    • If the destination file already exists, the operation will fail.
    • Ensure your app has the necessary file system permissions for the target directories.
    <?php
    // PHP Import
    use Native\
    Mobile\
    \Facades\
    File;
    
    // JS Import
    import { file } from '#nativephp';
  4. Use Shape primitives for drawing geometric forms

    main

    NativePHP provides three shape primitives for drawing simple geometric forms. These are typically used inside a <native:canvas> or as standalone decorative accents.

    Available primitives:

    • <native:rect>: A rectangle filled with a bg color.
    • <native:circle>: A circle filled with a bg color.
    • <native:line>: A horizontal rule.

    All shapes support shared layout and style attributes using Tailwind-style classes (e.g., rounded-*, border-*, opacity-*, shadow-*).

  5. Use the Dialog API for alerts and toasts

    main

    The Dialog API provides access to native platform dialogs (UIAlertController on iOS and AlertDialog on Android). It is a core built-in feature that requires no installation or registration. You can use it to show modal alerts with buttons or non-blocking toast/snackbar notifications.

    Import the facade to begin:

    use Native\	ext{Mobile}\\Facades\\Dialog;
    use Native\Mobile\Facades\Dialog;
  6. Use the Button Group component

    main

    The <native:button-group> is a segmented single-choice selector used for short, mutually-exclusive choices that fit on a single row. Each option appears as a pressable pill in a horizontal bar, with the active selection highlighted using theme.primary.

    For more options or longer labels, consider using <native:tab-row> or <native:select> instead.

    @php $period = 0; @endphp
    
    <native:button-group :options="['Daily', 'Weekly', 'Monthly']" native:model="period" />
  7. Use the File API for native file operations

    main

    The File API provides access to native file system operations like moving and copying files directly on the device. It is a core built-in feature of NativePHP Mobile, meaning no additional installation or registration is required. You can access it via the Native\Mobile\Facades\File facade in PHP or via the Native library in a JavaScript web view.

    use Native\Mobile\Facades\File;
  8. Use the Chip component

    main

    The Chip component is a compact, capsule-shaped selectable tag. It features a boolean active state and an optional leading icon.

    Visual States:

    • Selected: Fills with theme.primary and uses theme.onPrimary for content.
    • Unselected: Uses theme.surfaceVariant with a 1pt theme.outline stroke.

    Styling: Colors are derived from the theme. The capsule is fully rounded by default, but you can adjust the radius using standard rounded-* utility classes.

    @php $filterVerified = false; @endphp
    
    <native:chip label="Verified" icon="check" native:model="filterVerified" />