Final Documentation: A Complete Guide to Building Modular & Real-Time Dashboards in Laravel & Vue 2
Table of Contents
- System Architecture
- Part 1: The Server-Side Foundation (Laravel)
- 1.1. The Reusable Blade Component:
<x-chart-block />
- Part 2: The Client-Side Widgets (Vue “Bricks”)
- 2.1. Universal Chart Component:
ChartBlock.vue - 2.2. KPI Card Component:
KpiCard.vue
- Part 3: The Dashboard Canvas (Vue Layout Controller)
- 3.1. The Layout Component with Full-Screen Toggle:
DashboardLayout.vue
- Part 4: Implementation Patterns & Full Source Code
- 4.1. Pattern A: The Standard Live Dashboard (Axios Polling)
- Laravel Controller & Routes
- Vue Page Component
- Blade View
- 4.2. Pattern B: The Real-Time Dashboard (Server-Sent Events)
- Laravel Controller & Routes
- Vue Page Component
- Blade View
- Part 5: Project Setup & Configuration
- 5.1. Dependencies
- 5.2. Global Vue Component Registration (
app.js)
1. System Architecture
This system is built on a powerful separation of concerns:- Laravel (Backend): Responsible for data fetching, business logic, and initial page rendering. It provides data to the frontend in a structured format.
- Vue.js (Frontend): Responsible for rendering all interactive components, managing the UI state, and handling real-time data updates.
- Blade Components (The Bridge): A simple but effective way to initialize Vue components with server-rendered data, making them easy to use within traditional Laravel views.
data and params props, making them interchangeable and easy to manage.
Part 1: The Server-Side Foundation (Laravel)
1.1. The Reusable Blade Component: <x-chart-block />
This Blade component acts as a convenient wrapper to render the ChartBlock.vue component from your Blade files. It simplifies passing PHP data to Vue by handling the JSON encoding and component initialization.
How to Create:
app/View/Components/ChartBlock.php
resources/views/components/chart-block.blade.php
Part 2: The Client-Side Widgets (Vue “Bricks”)
These are the core visual building blocks of your dashboard.2.1. Universal Chart Component: ChartBlock.vue
File: resources/js/components/ChartBlock.vue
2.2. KPI Card Component: KpiCard.vue
File: resources/js/components/KpiCard.vue
Part 3: The Dashboard Canvas (Vue Layout Controller)
3.1. The Layout Component with Full-Screen Toggle: DashboardLayout.vue
File: resources/js/components/DashboardLayout.vue
Part 4: Implementation Patterns & Full Source Code
4.1. Pattern A: The Standard Live Dashboard (Axios Polling)
Laravel Controller & Routes
File:app/Http/Controllers/ReportController.php
Vue Page Component
File:resources/js/components/MyReportPage.vue
Blade View
File:resources/views/report.blade.php
4.2. Pattern B: The Real-Time Dashboard (Server-Sent Events)
Laravel SSE Controller & Routes
File:app/Http/Controllers/SseDashboardController.php
Vue Page Component
File:resources/js/components/SseDashboardPage.vue
Blade View
File:resources/views/sse-dashboard.blade.php
Part 5: Project Setup & Configuration
5.1. Dependencies
Ensure you have the necessary NPM packages installed.5.2. Global Vue Component Registration (app.js)
File: resources/js/app.js

