Search by

Vue UI integration for SahilPHP applications.

Package info

github.com/sahilphp/vue

pkg:composer/sahilphp/vue

Statistics

Installs: 17

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.2 2026-11-20 20:08 UTC

This package is not auto-updated.

Last update: 2026-11-20 20:09:26 UTC


README

A complete, independently installable SahilPHP application with a Vue 3 + TypeScript + Vite frontend. Controllers render Vue pages with ordinary PHP data; Vite handles development HMR and production builds.

Requirements

  • PHP 8.4+
  • Composer 2
  • Node.js 20.19+
  • npm 10+

Installation

Warning

This package is a library, not a project skeleton. composer create-project sahilphp/vue fails by design. Create a project with sahilphp new my-app and choose Vue during setup; the installer wires Vue, Vite and your CSS framework together.

Install it as a dependency with:

composer require sahilphp/vue

Create a new application with the installer:

sahilphp new my-app --ui-kit=vue --css=tailwind
cd my-app
npm install

For a checkout that already exists:

composer install
cp .env.example .env
php sahil key:generate
npm install

Development

Run PHP and Vite in separate terminals:

npm run dev          # Vite on http://127.0.0.1:5173
php sahil start      # PHP on http://127.0.0.1:8000

Open http://127.0.0.1:8000. The PHP-rendered document loads @vite/client and src/main.ts from the dev server, so Vue components hot reload. If Vite chooses another port, public/hot overrides frontend.dev_server.

Production build

npm run build

Vite writes public/build/ and public/build/.vite/manifest.json. Point the web server document root at public/. In production (APP_ENV=production) the PHP renderer reads the manifest, recursively collects imported CSS, verifies every referenced file and emits immutable script/style tags. No Vite server is needed at runtime.

Rendering from PHP

use App\Frontend\Vue;

final class HomeController
{
    public function response(): \Sahil\Http\Response
    {
        $data = [
            'app_name' => (string) $this->application->config()->get('app.name', 'SahilPHP'),
            'php_version' => PHP_VERSION,
        ];

        return Vue::render('pages.home', $data);
    }
}

Page names map predictably:

PHP page name Vue component sent to the browser File
pages.home Pages/Home.vue src/pages/Home.vue
pages.notFound Pages/NotFound.vue src/pages/NotFound.vue
pages.dashboard.index Pages/Dashboard/Index.vue src/pages/Dashboard/Index.vue

The leading pages segment is optional. Every other segment is PascalCased. A missing component fails with an exception naming the expected path.

Vue::render() returns a normal Sahil\Http\Response; use withStatus() or withHeader() for additional HTTP behaviour. The example 404 route does exactly that. The adapter is also registered as the vue unified-render environment, so Render::vue('pages.home', $data), $this->vue('pages.home', $data) in a controller and Response::vue('pages.home', $data) resolve the same pages.

Data safety

  • Data is JSON encoded with JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS and JSON_HEX_QUOT, so values such as </script> cannot escape the payload element.
  • The payload lives in <script type="application/json">, not executable JavaScript.
  • The component name, mount id, title, language and asset URLs are validated and HTML-escaped.
  • Only JSON-serializable data can be passed; encoding failures throw a clear VueRenderException.

Project structure

app/
  Frontend/            Vue page resolution, payload, Vite assets, renderer
  Http/                Controllers and middleware
  Providers/           Frontend and route/kernel wiring
bootstrap/             Application and provider manifests
config/                app.php, frontend.php, identification.php
public/                Front controller, .htaccess, public assets
routes/web.php         Route table
src/
  components/          Reusable Vue components (Nav, Card, Alert, FormField)
  layouts/             Shared AppLayout
  lib/payload.ts       Payload and component-name helpers
  pages/               Vue pages
  styles/global.css    Application styles
  main.ts              Client entry point (mount + fatal error UI)
tests/
  Feature/             HTTP integration and container/provider wiring
  Frontend/            Page resolution, payload rendering and Vite assets
  Support/             Isolated filesystem fixtures
  js/                  Vitest tests for helpers and component rendering

Example application

  • / — home page with PHP runtime data, features and getting-started code.
  • /example — nested objects, lists and request metadata passed to Vue.
  • /form — form with client-side and PHP-side validation feedback.
  • /health — JSON health endpoint.
  • Any unknown path — Vue not-found page with a real 404 status.

Tests and checks

composer test       # PHPUnit: rendering, assets, routing, form validation
npm test            # Vitest: payload helpers and Vue server rendering
npm run check       # vue-tsc / TypeScript
npm run build       # production asset build

Configuration

config/frontend.php controls the mount id, payload title key, language, development mode, dev server URL, build directory/public path, manifest location, entry point, asset verification and pages directory. Defaults are safe for local development and production builds.

config/identification.php controls the public framework fingerprint: the <meta name="generator" content="SahilPHP x.y.z"> tag injected into served documents and the X-Powered-By: SahilPHP response header. Set SAHIL_IDENTIFICATION=false (or identification.enabled to false) to disable both signals; SAHIL_POWERED_BY=false hides the header only.

starter-vue