Installation:
composer require pboivin/filament-peek:"^4.1"
Ensure you’re using Filament v3+ (compatible with Filament 3.x and 4.x).
Register the Plugin:
Add to your PanelProvider (e.g., app/Providers/Filament/AdminPanelProvider.php):
public function panel(Panel $panel): Panel {
return $panel
->plugins([
FilamentPeekPlugin::make(),
]);
}
Publish Assets:
php artisan filament:assets
This generates the modal UI and JavaScript.
First Use Case:
Add the Peekable trait to a Form or Table resource:
use Pboivin\FilamentPeek\Concerns\Peekable;
class PostResource extends Resource {
use Peekable;
// ...
}
Now, a "Preview" button appears in the top-right corner of the form.
Form Previews:
Peekable trait on Forms to enable preview before saving.peekUrl() method:
public function peekUrl(): string {
return route('posts.preview', $this->record);
}
Table Row Previews:
Peekable to Tables to preview records inline:
use Pboivin\FilamentPeek\Concerns\Peekable;
class PostTable extends Table {
use Peekable;
// ...
}
peekUrl() for dynamic routes (e.g., route('posts.show', $record)).Custom Preview Logic:
peekView():
public function peekView(): string {
return view('filament.peek.custom-preview', ['record' => $this->record]);
}
Conditional Peek:
public function canPeek(): bool {
return $this->record->isPublished();
}
peekUrl() returning an API endpoint).peekUrl() method in unit tests:
$resource->shouldReceive('peekUrl')->andReturn('/fake-preview');
Asset Publishing:
php artisan filament:assets after installation breaks the modal UI.php artisan view:clear).Route Conflicts:
peekUrl() returns a non-existent route, the modal fails silently.dd($this->peekUrl()) in peekUrl().Caching Issues:
peekView() or peekUrl() may not reflect due to Blade caching.php artisan filament:cache-clear
Permission Denied:
canPeek() returns true or adjust Filament’s policies.Inspect Modal Content:
Override peekView() to return a debug view:
public function peekView(): string {
return view('filament.peek.debug', [
'record' => $this->record,
'url' => $this->peekUrl(),
]);
}
This reveals the rendered URL and data passed to the preview.
Disable Peek Temporarily:
Comment out the Peekable trait to isolate issues.
Custom Modal Styling: Publish the package’s views and override them:
php artisan vendor:publish --tag="filament-peek-views"
Modify resources/views/vendor/filament-peek/modal.blade.php.
Event Hooks:
Listen for peek.opening or peek.closing events (if the package supports them) to add logic:
event(new FilamentPeekOpening($record, $url));
Multi-Tab Support:
For SPAs, ensure the modal closes when navigating away (e.g., via window.onbeforeunload).
How can I help you explore Laravel packages today?