Search by

dominservice / laravel-media-kit

dominservice

Laravel media library for reusable image and video assets, responsive image variants and admin media management.

Package info

github.com/dominservice/laravel-media-kit

pkg:composer/dominservice/laravel-media-kit

Statistics

Installs: 30

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

2.2.3 2026-10-22 11:16 UTC

This package is auto-updated.

Last update: 2026-11-23 20:27:32 UTC


README

Laravel Media Kit logo showing overlapping image frames with a mountain and sun

Laravel Media Kit stores reusable images and video in Laravel and delivers responsive image variants from a shared media library.

Developed by Mateusz Domin at Domin Software. Media Kit also provides the media layer for DominPress through its integration with Laravel CMS.

Latest Version on Packagist Total Downloads License

dominservice/laravel-media-kit is a reusable media layer for Laravel applications that need image and video processing, responsive variants and a shared admin media library.

It is designed to work well in two modes at once:

  • as a clean standalone media toolkit,
  • as the media backbone for dominservice/laravel-cms and larger modular systems.

Key Features

  • Laravel 13 support,
  • responsive image variants in AVIF, WebP, JPEG and PNG,
  • lazy or eager variant generation,
  • media kinds for domain-specific collections,
  • shared media library for admin panels,
  • attach existing assets without re-uploading the same file,
  • image and video support,
  • configurable admin routes, middleware, permissions and layout integration,
  • publishable package views for host-project theming,
  • CDN and signed URL support.

Requirements

  • PHP 8.3+
  • Laravel 13.32+

The current 2.x line targets DominPress and Laravel 13. Laravel 9–12 remain available through the previous 1.x line.

Installation

composer require dominservice/laravel-media-kit

php artisan vendor:publish --provider="Dominservice\MediaKit\MediaKitServiceProvider" --tag=mediakit-config
php artisan vendor:publish --provider="Dominservice\MediaKit\MediaKitServiceProvider" --tag=mediakit-migrations
php artisan vendor:publish --provider="Dominservice\MediaKit\MediaKitServiceProvider" --tag=mediakit-views

php artisan migrate

Quick Start

Add media to a model

use Dominservice\MediaKit\Traits\HasMedia;
use Dominservice\MediaKit\Traits\HasMediaKinds;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use HasMedia;
    use HasMediaKinds;
}
$asset = $post->addMedia($request->file('cover'), 'featured');

Pass the returned asset to your Blade view.

<x-media-picture :asset="$asset" variant="md" alt="Article cover" />

When variants are available, the component renders a <picture> with AVIF and WebP sources and a fallback image. With only the original asset, it renders an <img> pointing to the original.

Check image format support

Run php artisan media:diagnose to inspect GD, Imagick, WebP and AVIF support on the deployment host. Use an encoder with AVIF support before serving AVIF variants. In the current GD pipeline, the fallback can write WebP data to an .avif path when imageavif() is unavailable.

Reuse an existing asset

$post->attachExistingMedia($mediaAsset, 'featured');
$post->attachExistingMedia($uuid, 'gallery', 'keep');

This is useful for shared media libraries, CMS block builders and projects where the same asset may be used in many places.

Shared Admin Media Library

The package now includes an optional admin media library module.

It provides:

  • reusable routes and controllers inside the package,
  • upload, list and delete actions,
  • a dedicated media_libraries table,
  • publishable views,
  • flexible route, permission and layout integration.

Admin configuration

'admin' => [
    'enabled' => filter_var(env('MEDIA_KIT_ADMIN_ENABLED', false), FILTER_VALIDATE_BOOL),
    'prefix' => 'admin/media',
    'route_name_prefix' => 'admin.media.',
    'middleware' => ['web', 'auth'],
    'permissions' => [
        'view' => 'media.view',
        'upload' => 'media.upload',
        'delete' => 'media.delete',
    ],
    'layout' => [
        'mode' => 'extends',
        'view' => 'layouts.admin',
        'section' => 'content',
        'component' => 'admin-layout',
    ],
    'library' => [
        'view' => 'mediakit::admin.library.index',
        'default_key' => 'global',
        'default_name' => 'Main media library',
        'default_collection' => 'library',
        'per_page' => 18,
    ],
],

The admin library is disabled by default. Enable it explicitly in a host project with MEDIA_KIT_ADMIN_ENABLED=true. The public media delivery route remains available, because CMS pages may still need to render stored assets without exposing the admin library.

This keeps the route and controller logic inside the package while allowing the project to override only the Blade views.

CMS Integration

dominservice/laravel-cms can use Media Kit as its media backend.

Recommended setup:

  • keep media library routes and controller inside laravel-media-kit,
  • keep CMS content logic inside laravel-cms,
  • publish views from both packages,
  • override the views in the project to match the design system.

This gives you a reusable package architecture and avoids duplicating media logic per project.

Kinds and Variants

Kinds let you define domain-aware media contracts such as avatar, gallery, video_avatar or video_poster.

'kinds' => [
    'avatar' => [
        'collection' => 'avatar',
        'display' => 'lg',
        'variants' => ['thumb', 'sm', 'md', 'lg'],
    ],
    'video_avatar' => [
        'collection' => 'video',
        'renditions' => ['hd', 'sd', 'mobile'],
        'poster_kind' => 'video_poster',
    ],
],

Views and Theming

The package is prepared for reuse across projects.

php artisan vendor:publish --provider="Dominservice\MediaKit\MediaKitServiceProvider" --tag=mediakit-views

Recommended approach:

  • keep routes, controller actions, models and services in the package,
  • publish the views,
  • override only the UI layer in the host project.

This is especially useful when pairing Media Kit with a custom CMS or admin template such as Metronic.

Extensibility

The package is intentionally configurable instead of hardcoded.

You can override:

  • models,
  • route prefix and route names,
  • admin middleware and permissions,
  • layout mode and view integration,
  • accepted file extensions,
  • kinds and variants,
  • published views.

This allows each project to adapt the package without forking the package logic.

Support

Report package issues on GitHub.

If this package helps you, you can buy me a coffee to support its maintenance.

Buy me a coffee on Ko-fi

License

MIT