Debugging InspireCMS
This guide provides effective techniques for troubleshooting and debugging issues in InspireCMS.
Enabling Debug Mode
For development environments, enable debug mode to get detailed error messages:
// .env
APP_DEBUG=true
APP_ENV=local
Warning: Never enable debug mode in production environments as it exposes sensitive information.
Debugging Techniques
Laravel Debugging Tools
Dump and Die
Use Laravel's built-in helper functions for quick debugging:
// Simple value dump and die
dd($variable);
// Dump multiple values without stopping execution
dump($variable1, $variable2);
// Continue execution...
// Dump when rendering a view
<div>{{ dump($variable) }}</div>
Debug Bar
Install Laravel Debugbar for enhanced debugging:
composer require barryvdh/laravel-debugbar --dev
This adds a debug panel to your site showing:
- Queries executed
- Request information
- View rendering time
- Session data
- Cache operations
Tinker
Use Laravel's Tinker to interact with your application from the command line:
php artisan tinker
Examples:
// Check if content exists
\SolutionForest\InspireCms\Models\Content::count();
// Test content retrieval
inspirecms_content()->findByIds(ids: '550e8400-e29b-41d4-a716-446655440000', limit: 1);
// Check template configuration
inspirecms_templates()->getCurrentTheme();
InspireCMS Specific Debugging
System Information
Get system details to help with debugging:
php artisan inspirecms:about
Test Templates
Test template rendering in isolation:
// In a controller or route
$content = inspirecms_content()->findByIds(ids: 'content-id', limit: 1)->first();
$template = $content->getDefaultTemplate() ?? $content->documentType?->getDefaultTemplate();
$theme = inspirecms_templates()->getCurrentTheme();
$templateDto = $template?->toDto($theme);
return $templateDto->render([
'content' => $content,
]);
Component Testing
Check if components are registered correctly:
// In Tinker or controller
$hasComponent = inspirecms_templates()->hasComponent('header', 'your-theme');
dd($hasComponent);
Advanced Debugging Techniques
Logging to File
Add custom logging statements to trace execution:
\Log::debug('Debugging content retrieval', [
'content_id' => $content->id,
'properties' => $content->getLatestVersionPropertyData(),
]);
Using Clock Helper
Add timing information to debug performance issues:
use Illuminate\Support\Facades\Log;
$startTime = microtime(true);
// Operation to measure
$endTime = microtime(true);
Log::info('Operation took: ' . ($endTime - $startTime) . ' seconds');
Creating a Test Route
Create a temporary debug route in routes/web.php:
Route::get('/_debug/test-template/{id}', function ($id) {
$content = inspirecms_content()->findByIds(ids: $id, limit: 1)->first();
if (!$content) {
return 'Content not found';
}
return [
'content' => [
'id' => $content->id,
'title' => $content->getTitle(),
'document_type' => $content->document_type,
'has_property' => $content->hasProperty('content', 'body'),
'property_value' => $content->getPropertyValue('content', 'body'),
],
'template' => inspirecms_templates()->getCurrentTheme(),
'components' => [
'has_page' => inspirecms_templates()->hasComponent('page'),
'has_layout' => inspirecms_templates()->hasComponent('layout'),
],
];
})->middleware('auth');
Debug Front-End Components
Add temporary debug output to Blade templates:
<!-- resources/views/components/inspirecms/your-theme/page.blade.php -->
<div style="background: #f8d7da; padding: 10px; margin: 10px; border: 1px solid #f5c6cb; display: none;">
<strong>Debug:</strong>
<pre>{{ print_r(['content' => $content ? $content->toArray() : null, 'locale' => $locale ?? null], true) }}</pre>
<button onclick="this.parentNode.style.display = 'block'">Show Debug</button>
</div>
Backend Debugging Tools
Using Xdebug
For in-depth debugging, configure Xdebug with your IDE:
- Install Xdebug with PHP
- Configure your
php.ini:
[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.start_with_request=yes
- Configure your IDE (PHPStorm, VSCode) to listen for Xdebug connections
- Set breakpoints in your code and run your application
Query Debugging
Debug database queries:
// Log all queries for a code block
\DB::enableQueryLog();
// Your code that executes queries
$content = inspirecms_content()->findByIds(ids: 'id', limit: 1)->first();
// Get the query log
$queries = \DB::getQueryLog();
dd($queries);
Frontend Debugging
Browser Developer Tools
Use browser developer tools for frontend debugging:
-
Chrome DevTools / Firefox Developer Tools:
- Network tab to check asset loading
- Console for JavaScript errors
- Elements tab to inspect HTML structure
-
JavaScript Debugging:
- Add
console.log()statements - Set breakpoints in browser DevTools
- Add
Troubleshooting Templates
If templates aren't rendering correctly:
// Test direct rendering of components
@php
try {
echo view('components.inspirecms.your-theme.header', ['locale' => app()->getLocale()])->render();
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
@endphp
Debugging Custom Extensions
When debugging custom resources or pages:
// Create a debug route for your custom resource
Route::get('/_debug/my-resource', function () {
$class = \App\Filament\Resources\CustomResource::class;
return [
'exists' => class_exists($class),
'registered' => in_array(
$class,
collect(config('inspirecms.admin.resources'))->values()->toArray()
),
];
});
Performance Debugging
Memory Usage
Track memory usage:
$initialMemory = memory_get_usage();
// Code to profile
$peakMemory = memory_get_peak_usage();
$usedMemory = memory_get_usage() - $initialMemory;
Log::info('Memory usage', [
'used' => round($usedMemory / 1024 / 1024, 2) . ' MB',
'peak' => round($peakMemory / 1024 / 1024, 2) . ' MB',
]);
Request Profiling
For advanced profiling, use Laravel Telescope:
composer require laravel/telescope --dev
php artisan telescope:install
php artisan migrate
Access Telescope at /telescope to view detailed metrics on:
- Requests and responses
- Database queries
- Cache operations
- Model operations
Troubleshooting Environment Issues
Testing PHP Configuration
Create a diagnostic file to check your environment:
// public/phpinfo.php
<?php
phpinfo();
Testing File Permissions
# See if PHP can write to storage
php -r "file_put_contents(storage_path('test.txt'), 'test');"
php -r "echo file_exists(storage_path('test.txt')) ? 'Success' : 'Failed';"
php -r "@unlink(storage_path('test.txt'));"
Next Steps
If you're still experiencing issues after using these debugging techniques:
- Check specific error messages against the Common Issues guide
- Review the Logs & Error Handling documentation
- Reach out to the community using our Support Resources