Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Filament Action Preview Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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"
    
  2. Basic Usage Register the preview action in your Filament resource:

    use Novius\FilamentActionPreview\Actions\PreviewAction;
    
    public static function getActions(): array
    {
        return [
            PreviewAction::make(),
        ];
    }
    
  3. First Use Case

    • Add the action to a Filament resource page (e.g., Index, Edit, or View).
    • Click the preview button to open the frontend URL of the resource model.

Implementation Patterns

Common Workflows

  1. Dynamic Preview URLs Override the default URL logic in your resource:

    PreviewAction::make()
        ->url(fn ($record) => route('frontend.preview', $record->slug))
    
  2. Conditional Visibility Show/hide the action based on record state:

    PreviewAction::make()
        ->visible(fn ($record) => $record->isPublished())
    
  3. Customizing the Action Rename the button or add icons:

    PreviewAction::make()
        ->label('Live Preview')
        ->icon('heroicon-o-eye')
    
  4. 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(),
        ];
    }
    
  5. 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
    

Gotchas and Tips

Pitfalls

  1. URL Resolution Issues

    • Ensure your frontend routes are properly defined and accessible.
    • Debug with dd($record->toArray()) to verify model data before previewing.
  2. Caching Conflicts

    • Clear Filament cache if the action doesn’t appear:
      php artisan filament:cache:clear
      
  3. Permission Denied

    • The action respects Filament’s built-in policies. Ensure the user has access to the resource.
  4. AGPL License Implications

    • If your project is not AGPL-compatible, consider forking the package or using an alternative.

Debugging Tips

  • 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.

Extension Points

  1. 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]);
        }
    }
    
  2. Event-Based Triggers Dispatch events before/after previewing:

    PreviewAction::make()
        ->before(fn ($record) => event(new Previewing($record)))
        ->after(fn ($record) => event(new Previewed($record)))
    
  3. Localization Translate labels/icons:

    PreviewAction::make()
        ->label(__('filament-preview::actions.preview'))
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity