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

Filament Media Action Laravel Package

hugomyb/filament-media-action

Filament action to preview media (video, audio, PDF, images, etc.) anywhere in your app (forms, tables, infolists, prefix/suffix). Just pass a media URL and it auto-detects the extension to render the right player/viewer.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require hugomyb/filament-media-action
    

    For Filament v3, use composer require hugomyb/filament-media-action:^3.0.

  2. First Use Case: Add a media action to a Filament resource table or form:

    use Hugomyb\FilamentMediaAction\Actions\MediaAction;
    
    MediaAction::make('Play Video')
        ->iconButton()
        ->icon('heroicon-o-video-camera')
        ->media('https://example.com/video.mp4');
    

Where to Look First

  • README.md: Focus on the "Usage" section for basic syntax.
  • Supported Media Types: Check the table in the README for extension compatibility.
  • Changelog: Review v4.1.0.0+ for media type constants and fixes.

Implementation Patterns

Common Workflows

  1. Table Actions:

    Tables\Actions\Action::make('View Media')
        ->action(MediaAction::make('media')
            ->media(fn($record) => $record->media_url)
            ->modalHeading(fn($record) => $record->title)
        );
    
  2. Form Fields:

    use Filament\Forms\Components\Actions\Action;
    
    Action::make('Preview')
        ->action(MediaAction::make('preview')
            ->media(fn($get, $record) => $get('media_url') ?? $record->media_url)
        );
    
  3. Nested Media Actions:

    MediaAction::make('Main Media')
        ->media(fn($record) => $record->primary_url)
        ->extraModalFooterActions([
            MediaAction::make('Secondary Media')
                ->media(fn($record) => $record->secondary_url),
        ]);
    

Integration Tips

  • Dynamic URLs: Use closures to fetch URLs from records or forms:
    ->media(fn($record) => $record->getMediaUrl())
    
  • Conditional Logic: Leverage closures for autoplay/controls:
    ->autoplay(fn($record, $mediaType) => $mediaType === 'video' && $record->is_premium)
    
  • Modal Customization: Extend Filament’s modal options:
    ->modalWidth('6xl')
    ->modalMaxWidth('100%')
    

Gotchas and Tips

Pitfalls

  1. Media Type Detection:

    • Local URLs (e.g., http://myapp.test/video.MOV) may fail auto-detection. Use ->mediaType(MediaAction::TYPE_VIDEO) to force the type.
    • Fix: Always test with local URLs in development.
  2. Closure Dependencies:

    • In non-schema contexts (e.g., page actions), $get/$set may be null. Guard closures:
      ->media(fn($get, $record) => $get ? $get('url') : $record->url)
      
  3. YouTube Embeds:

    • Autoplay may be blocked. Use ->preload(false) to avoid browser errors.
  4. MIME Type Conflicts:

    • Forcing a media type (e.g., ->mediaType('video')) may cause "Loading..." issues if the MIME type is invalid. Prefer constants:
      ->mediaType(MediaAction::TYPE_VIDEO)
      

Debugging Tips

  • Check the Network Tab: Verify media URLs are accessible and return correct MIME types.
  • Log Media Types: Debug the detected type:
    ->media(fn($record) => {
        $url = $record->url;
        $type = app(MediaAction::class)->getMediaType($url);
        logger()->debug("Detected type for $url: $type");
        return $url;
    })
    
  • Publish Views: Customize the modal template if default rendering is insufficient:
    php artisan vendor:publish --tag="filament-media-action-views"
    

Extension Points

  1. Custom Players:

    • Override the default view (resources/views/vendor/filament-media-action/modal.blade.php) to integrate third-party players (e.g., Plyr, Video.js).
  2. Translation:

    • Publish translations for multilingual support:
      php artisan vendor:publish --tag="filament-media-action-translations"
      
  3. Media Type Extensions:

    • Extend the getSupportedExtensions() method in MediaTypeDetector (via service provider binding) to support custom formats.

Performance Notes

  • Preload: Disable ->preload(true) for large media to reduce initial load time.
  • Lazy Loading: Use ->modalMaxWidth('100%') to defer modal rendering until clicked.
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.
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
christhompsontldr/laravel-inky