LaraflareDocsPackages13.x

Docs / Getting Started / Frontend

Frontend

Introduction

Laraflare is a backend framework that provides all of the features you need to build modern web applications, such as routing, validation, caching, queues, file storage, and more. It also offers a full-stack experience, including a ready-made approach for building your application's frontend.

Where other frameworks offer several ways to build a frontend, Laraflare has one: your application's screens are Vue components, bundled with Vite and styled with Tailwind, and your routes and controllers answer the JSON requests those screens make.

Using Vue

A new Laraflare application keeps its frontend in resources/js: app.ts creates the Vue application, pages holds the screens, and layouts, components and composables hold the pieces they share. The page shell is index.html, which Vite uses as its entry.

Screens and Routes

A screen is a Vue component in resources/js/pages. The browser's address is matched to a screen by the client-side router in resources/js/router.ts, so moving between screens never loads a new HTML document. A screen reads and changes its data by calling your application's routes, which are written in routes/web.ts and handled by controllers in app/Http/Controllers, as usual:

<script setup lang="ts">
import Head from '@/components/Head.vue';
</script>

<template>
    <Head title="Welcome" />

    <h1>Welcome</h1>
</template>

The URLs a screen needs, both its own screens and the JSON endpoints it calls, are written out as small functions in resources/js/routes.ts, such as dashboard() and login(), so a URL is spelled in one place:

import { dashboard } from '@/routes';

dashboard(); // '/dashboard'

Note

The Worker serves the built index.html for every navigation that matches no file (the single-page-application mode set in wrangler.toml), and npx artisan serve does the same locally. A screen's data comes from the request it makes after it loads, not from the server rendering it.

No Blade, No Livewire, No Inertia

Laraflare has no Blade templates, no Livewire components and no Inertia pages: a controller returns data (such as JSON), never a rendered view, and there is no server-side rendering. If you are porting an application that renders its screens on the server, rewrite each one as a Vue component in resources/js/pages.

Bundling Assets

Your application's CSS and your Vue components must be bundled into production-ready assets. Laraflare uses Vite for this. Vite provides lightning-fast build times and near instantaneous Hot Module Replacement (HMR) during local development. In every new Laraflare application you will find a vite.config.ts file that loads the Vue and Tailwind plugins.

Locally, Valet starts Vite when it is needed, so open your application at its .test address. If you are not using Valet, npm run dev starts the development server. npm run build bundles the assets into public/build, and ship builds them when it takes your application live (see deployment).

Adapted from Laravel's documentation, Copyright (c) Taylor Otwell, used under the MIT License.