Laravel Debugbar integration for Vue.js SPA applications
npm install vue3-spa-laravel-debugbarA Vue.js plugin that integrates Laravel Debugbar with Vue SPA applications, providing the same debugging experience as traditional Laravel applications.
- 🐛 Full Laravel Debugbar Integration - Access all debugbar data in your Vue SPA
- 🔄 Multiple Request Tracking - View debug data from multiple API calls
- 🎯 Request Selector - Switch between different requests with a dropdown
- ⚡ Auto HTTP Intercepting - Automatically capture debugbar data from axios requests
- 🎨 Customizable UI - Built-in debug panel component with toggle functionality
- 📱 Development Only - Automatically disabled in production
- 🔧 TypeScript Support - Full TypeScript definitions included
``bash`
npm install vue-laravel-debugbar
First, install Laravel Debugbar in your Laravel backend:
`bash`
composer require barryvdh/laravel-debugbar --dev
Create a middleware to include debugbar data in API responses:
` namespace App\Http\Middleware; use Closure; class DebugbarMiddleware if (config('app.debug')&& class_exists(\Debugbar::class) && \Debugbar::isEnabled() && $request->wantsJson()) { // Generate unique request ID // Store request info $renderer = $debugbar->getJavascriptRenderer(); $originalContent = $response->getOriginalContent(); $debugData = [ if (is_array($originalContent)) { return $response;php`
// app/Http/Middleware/DebugbarMiddleware.php
use Illuminate\Http\Request;
{
public function handle(Request $request, \Closure $next)
{
$response = $next($request);
$debugbar = app('debugbar');
$requestId = uniqid('req_', true);
$requestInfo = [
'id' => $requestId,
'method' => $request->method(),
'url' => $request->fullUrl(),
'time' => now()->format('H:i:s'),
'timestamp' => microtime(true),
'status' => $response->getStatusCode(),
];
$renderer->setBaseUrl('http://localhost:8000');
$renderer->setOpenHandlerUrl('http://localhost:8000/_debugbar/open');
'request_info' => $requestInfo,
'debugbar_html' => $renderer->renderHead() . $renderer->render(),
'debugbar_data' => $debugbar->getData() // Raw data for analysis
];
$originalContent['_debugbar'] = $debugData;
$response->setContent(json_encode($originalContent));
} else {
$data = json_decode($response->getContent(), true) ?: [];
$data['_debugbar'] = $debugData;
$response->setContent(json_encode($data));
}
}
}
}
Register the middleware in your app/Http/Kernel.php:
`php`
protected $middlewareGroups = [
'api' => [
// ... other middleware
\App\Http\Middleware\DebugbarMiddleware::class,
],
];
#### Option A: Using the Vue Plugin (Recommended)
`javascript
// main.js
import { createApp } from 'vue'
import VueLaravelDebugbar from 'vue-laravel-debugbar'
import axios from 'axios'
import App from './App.vue'
const app = createApp(App)
app.use(VueLaravelDebugbar, {
baseURL: 'http://localhost:8000',
enabled: process.env.NODE_ENV === 'development',
axios: axios, // Optional: auto-setup interceptors
})
app.mount('#app')
`
Then use the debug panel in your components:
`vue`
My App
#### Option B: Using Composables
`vue`
#### Option 3: Manual Integration
`javascript
import { useDebugbar, createHttpInterceptor } from 'vue-laravel-debugbar'
import axios from 'axios'
// Setup axios with debugbar interceptor
const http = createHttpInterceptor(axios, {
baseURL: 'http://localhost:8000',
enabled: true
})
// Use in your components
const { debugbarRequests, showDebugbarToggle } = useDebugbar()
`
Main composable for debugbar functionality.
Parameters:
- options - Optional configuration object
Returns:
- debugbarRequests - Ref array of all captured requestscurrentRequestId
- - Ref of currently selected request IDisDebugbarVisible
- - Ref boolean of debugbar visibilityaddDebugbarData(data)
- - Function to add debugbar datashowDebugbar()
- - Function to show debugbarhideDebugbar()
- - Function to hide debugbarclearAllRequests()
- - Function to clear all requestsshowDebugbarToggle()
- - Function to toggle debugbar visibilitygetRequestStats()
- - Function to get current request statistics
`javascript`
{
baseURL: 'http://localhost:8000', // Laravel backend URL
enabled: true, // Enable/disable debugbar
autoShow: true, // Auto-show on first request
registerComponents: true, // Register components globally
axios: axiosInstance // Axios instance for auto-interceptor
}
####
A ready-to-use debug panel component with toggle button and request counter.
`vue`
`javascript
import { createFetchInterceptor } from 'vue-laravel-debugbar'
// For fetch API
const restoreFetch = createFetchInterceptor({
enabled: process.env.NODE_ENV === 'development'
})
// Later, if needed
restoreFetch() // Restores original fetch
`
`typescript
import { useDebugbar, DebugbarConfig } from 'vue-laravel-debugbar'
const config: DebugbarConfig = {
baseURL: 'http://localhost:8000',
enabled: true
}
const { addDebugbarData } = useDebugbar(config)
`
`javascript
const { getRequestStats } = useDebugbar()
const stats = getRequestStats()
console.log(Queries: ${stats.queries}, Memory: ${stats.memory})`
data
- Verify the middleware is registered and working
- Make sure you're in development mode$3
- Add debugbar assets to CORS allowed origins
- Ensure /_debugbar/* routes are accessible$3
- Check the baseURL configuration matches your Laravel backend
- Verify Laravel Debugbar assets are publishedContributing
1. Fork the repository
2. Create your feature branch (
git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add some amazing feature')
4. Push to the branch (git push origin feature/amazing-feature)
5. Open a Pull RequestCSS Styling
If you're using a bundler that doesn't automatically handle CSS imports, you can import the CSS file directly:
`javascript
// Import the CSS (use one of these options)
import 'vue3-spa-laravel-debugbar/style'; // Recommended
// OR
import 'vue3-spa-laravel-debugbar/dist/bundle.css'; // Direct path
// OR for minified version
import 'vue3-spa-laravel-debugbar/style.min';// Then use the components
import { DebugPanel } from 'vue3-spa-laravel-debugbar';
``