kirschbaum-development/filament-diffs
Installation
composer require kirschbaum-development/filament-diffs
Publish the config (if needed):
php artisan vendor:publish --provider="KirschbaumDevelopment\FilamentDiffs\FilamentDiffsServiceProvider"
Register the Plugin
In your AppServiceProvider or Filament panel configuration:
use KirschbaumDevelopment\FilamentDiffs\FilamentDiffsPlugin;
FilamentDiffsPlugin::make()
->register();
First Use Case Display raw file content in an Infolist:
use KirschbaumDevelopment\FilamentDiffs\Components\FileEntry;
FileEntry::make('Code Snippet')
->content(fn ($record) => $record->code)
->language('php') // Optional: auto-detects if omitted
->columnSpanFull(),
FileEntry::make('README.md')
->content('```markdown\n# Hello World\n```')
->language('markdown'),
FileEntry::make('User Script')
->content(fn ($record) => $record->script)
->language('javascript'),
Compare two versions (e.g., old vs new):
use KirschbaumDevelopment\FilamentDiffs\Components\FileDiffEntry;
FileDiffEntry::make('Version Comparison')
->oldContent(fn ($record) => $record->old_version)
->newContent(fn ($record) => $record->new_version)
->language('yaml')
->columnSpanFull(),
Use FileEntry in Forms for editing code snippets:
use KirschbaumDevelopment\FilamentDiffs\Components\FileEntry;
FileEntry::make('Configuration')
->content(fn ($record) => $record->config)
->language('json')
->required()
->columnSpanFull(),
Override default language detection or themes:
FileEntry::make('Custom Theme')
->content('...')
->language('php')
->theme('dark+') // Options: 'default', 'dark', 'dark+', 'light+'
->columnSpanFull(),
Show diffs only when changes exist:
FileDiffEntry::make('Changes')
->oldContent(fn ($record) => $record->previous_content)
->newContent(fn ($record) => $record->current_content)
->visible(fn ($record) => $record->has_changes),
Embed diffs in Filament Tables for row-level comparisons:
use KirschbaumDevelopment\FilamentDiffs\Components\FileDiffEntry;
Table::column(
FileDiffEntry::make('Diff')
->oldContent(fn ($record) => $record->old_data)
->newContent(fn ($record) => $record->new_data)
->language('json')
->width('100%'),
),
Format JSON/API responses for readability:
FileEntry::make('API Response')
->content(fn ($record) => json_encode($record->response, JSON_PRETTY_PRINT))
->language('json')
->columnSpanFull(),
Performance with Large Files
->maxLines(100) to truncate or pre-process content server-side.Language Auto-Detection Failures
@pierre/diffs may misidentify languages (e.g., text/plain for unknown files).->language('text') // Fallback
Dark Mode Inconsistencies
->theme(app()->environment('local') ? 'dark+' : 'light+')
Caching Static Diffs
->cacheFn(fn ($record) => $record->diff_cache_key)
Inspect Raw Content
Log the input to @pierre/diffs to debug rendering:
->content(fn ($record) => {
\Log::debug('Diff Input:', ['content' => $record->content]);
return $record->content;
}),
Validate Language Support
Check supported languages in @pierre/diffs. Unsupported languages render as plain text.
Clear Filament Cache After updates, run:
php artisan filament:cache-reset
Custom Diff Algorithms Override the diff engine by binding a custom service:
$this->app->bind(
\KirschbaumDevelopment\FilamentDiffs\Contracts\DiffEngine::class,
fn () => new CustomDiffEngine()
);
Add New Themes
Extend the theme() method by publishing and modifying the plugin’s assets:
php artisan vendor:publish --tag=filament-diffs-assets
Localization Translate labels (e.g., "Added", "Removed") by publishing the language files:
php artisan vendor:publish --tag=filament-diffs-translations
How can I help you explore Laravel packages today?