novius/laravel-filament-action-preview
Add a Filament table action that opens a front-end preview URL for a resource record. Works with a model previewUrl() method or a custom URL callback via using(). Supports Laravel 11+ and Filament v4.
Installation
composer require novius/laravel-filament-action-preview
Publish the config (if needed):
php artisan vendor:publish --provider="Novius\FilamentActionPreview\FilamentActionPreviewServiceProvider" --tag="filament-action-preview-config"
Basic Usage Register the preview action in your Filament resource:
use Novius\FilamentActionPreview\Actions\PreviewAction;
public static function getActions(): array
{
return [
PreviewAction::make(),
];
}
First Use Case
Index, Edit, or View).Dynamic Preview URLs Override the default URL logic in your resource:
PreviewAction::make()
->url(fn ($record) => route('frontend.preview', $record->slug))
Conditional Visibility Show/hide the action based on record state:
PreviewAction::make()
->visible(fn ($record) => $record->isPublished())
Customizing the Action Rename the button or add icons:
PreviewAction::make()
->label('Live Preview')
->icon('heroicon-o-eye')
Integration with Filament Forms
Use the action in a Form or Table context:
use Novius\FilamentActionPreview\Actions\PreviewAction;
public static function tableActions(): array
{
return [
PreviewAction::make(),
];
}
Batch Preview (Advanced) Extend the package to support bulk previews (requires custom logic):
PreviewAction::make()
->action(fn (array $records) => redirect()->to(route('frontend.preview', $records[0]->slug)))
->visible(fn () => false) // Disable by default
URL Resolution Issues
dd($record->toArray()) to verify model data before previewing.Caching Conflicts
php artisan filament:cache:clear
Permission Denied
AGPL License Implications
Log the Generated URL
Override the url method to log the output:
PreviewAction::make()
->url(fn ($record) => {
$url = route('frontend.preview', $record->slug);
\Log::info('Preview URL:', ['url' => $url]);
return $url;
})
Check for Middleware Conflicts
If the preview URL returns 403, verify frontend middleware (e.g., auth, verified) isn’t blocking access.
Custom Preview Logic Extend the action class to add logic like:
use Novius\FilamentActionPreview\Actions\PreviewAction;
class CustomPreviewAction extends PreviewAction
{
protected function getUrl($record): string
{
return route('custom.preview.route', ['id' => $record->id, 'token' => $record->preview_token]);
}
}
Event-Based Triggers Dispatch events before/after previewing:
PreviewAction::make()
->before(fn ($record) => event(new Previewing($record)))
->after(fn ($record) => event(new Previewed($record)))
Localization Translate labels/icons:
PreviewAction::make()
->label(__('filament-preview::actions.preview'))
How can I help you explore Laravel packages today?