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

Media Laravel Package

moox/media

View on GitHub
Deep Wiki
Context7

Moox Media Package

A comprehensive media management package for FilamentPHP with translation support.

Installation

Install the package using the Moox installer:

php artisan moox:install

This will:

  • Publish migrations and configuration files
  • Publish Spatie Media Library configuration
  • Integrate the custom Media model and PathGenerator

Features

  • Media Management: Upload, organize, and manage media files with Spatie Media Library integration
  • Translations: Full translation support for media metadata
  • MediaPicker Component: Filament form component for selecting and attaching media to models
  • Media Collections: Organize media into collections with translation support

Usage

Setup Model for Media

To use media in your model, you need to:

  1. Use the HasMediaUsable trait
  2. Implement HasMedia interface
  3. Use InteractsWithMedia trait from Spatie Media Library
  4. Add a JSON field for storing media metadata (e.g., image)
  5. Optionally add a relation method to access media through usables

Example:

use Illuminate\Database\Eloquent\Model;
use Moox\Media\Traits\HasMediaUsable;
use Spatie\Image\Enums\Fit;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class Draft extends Model implements HasMedia
{
    use HasMediaUsable, InteractsWithMedia;

    protected $fillable = [
        'image', // JSON field for media metadata
        // ... other fields
    ];

    protected $casts = [
        'image' => 'json',
        // ... other casts
    ];

    // Optional: Access media through usables relation
    public function mediaThroughUsables()
    {
        return $this->belongsToMany(
            Media::class,
            'media_usables',
            'media_usable_id',
            'media_id'
        )->where('media_usables.media_usable_type', '=', static::class);
    }

    // Optional: Register media conversions
    public function registerMediaConversions(?Media $media = null): void
    {
        $this->addMediaConversion('preview')
            ->fit(Fit::Contain, 300, 300);
    }
}

Use MediaPicker in Filament Forms

use Moox\Media\Forms\Components\MediaPicker;

MediaPicker::make('image')
    ->multiple(false)
    ->acceptedFileTypes(['image/jpeg', 'image/png'])

Access Media Metadata

When media is attached via MediaPicker, the JSON field contains:

{
    "file_name": "example.jpg",
    "title": "Example Image",
    "alt": "Example Image",
    "description": "Image description",
    "internal_note": "Internal notes"
}

Editing Media Metadata

When editing media in the admin panel, fields like title, alt, description, and internal_note are automatically saved as soon as you leave the field (blur event). No save button is required - changes are persisted immediately and synchronized to all models using that media.

Requirements

  • Laravel 12+
  • Filament 4+
  • Spatie Media Library
  • Astrotomic Translatable
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.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed