Search by

rawbinn / media

Media library for Laravel — uploads, storage, image variants, and file manager.

Maintainers

Package info

github.com/rawbinn/media

pkg:composer/rawbinn/media

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-09-06 17:45 UTC

This package is auto-updated.

Last update: 2026-09-06 17:47:57 UTC


README

A standalone media library for Laravel. Upload files, store metadata, generate image variants, and serve cached resized images.

Requirements

  • PHP 8.3+
  • Laravel 13+
  • GD or Imagick (for image processing)

Installation

composer require rawbinn/media
php artisan vendor:publish --tag=media-config
php artisan migrate
php artisan vendor:publish --tag=media-assets

Laravel auto-registers the service provider and Media facade.

Quick start

1. Configure

// config/media.php
return [
    'disk' => 'public',
    'folder' => 'uploads',
    'max_file_size' => 10_485_760,
    'model' => \Rawbinn\Media\Models\Media::class,
    'user_model' => \App\Models\User::class,
    'users_table' => 'users',
];

2. Extend the model (optional)

namespace App\Models;

use Rawbinn\Media\Models\Media as BaseMedia;

class Media extends BaseMedia
{
    protected $fillable = [
        ...parent::getFillable(),
        'alt_text',
    ];
}
'model' => \App\Models\Media::class,

Use media_model() anywhere you need the configured class:

media_model()::find($id);

3. Helpers

media($id);                 // URL for media ID
media($id, '200x200');      // Cached resize URL
media_url('path/to/file');  // Storage URL for a path
media_disk();               // Configured filesystem disk

4. Image cache service

use Rawbinn\Media\Facades\Media;

return Media::cache('uploads/photo.jpg', '300x200');

Routes

Routes are enabled by default and can be customized:

'routes' => [
    'enabled' => env('MEDIA_ROUTES_ENABLED', true),
    'admin' => [
        'enabled' => true,
        'prefix' => 'admin',
        'middleware' => ['web', 'auth'],
    ],
    'cache' => [
        'enabled' => true,
        'prefix' => 'image',
        'middleware' => ['web'],
    ],
],

Admin routes:

  • POST admin/filemanager/upload
  • GET admin/filemanager/files
  • GET admin/filemanager/download/{id}
  • DELETE admin/filemanager/{id}
  • POST admin/image/upload

Public cache route:

  • GET image/{path}/{dimension?}

Disable all package routes:

MEDIA_ROUTES_ENABLED=false

Security

'security' => [
    'enforce_ownership' => true,  // Restrict download/preview/delete to owner
    'verify_mime' => true,        // Validate MIME type against extension
    'signed_downloads' => false,  // Require signed URLs for downloads
],

When signed_downloads is enabled, generate temporary links with:

$media->signedDownloadUrl(30); // minutes

Events

Listen for package lifecycle hooks:

use Rawbinn\Media\Events\MediaUploaded;
use Rawbinn\Media\Events\MediaDeleted;

Event::listen(MediaUploaded::class, function (MediaUploaded $event) {
    // $event->media
});

File manager UI

The bundled uploader uses rawbinn-* class names. Legacy Larapress views using data-toggle="seshra-uploader" remain supported.

Publishing

Tag Description
media-config Publish config/media.php
media-assets Publish file manager CSS/JS to public/vendor/rawbinn/media/assets

Testing

From the package directory:

composer install
composer test

From the monorepo root:

composer test:media

Larapress integration

Larapress consumes this package for admin media management. Set Larapress-specific middleware in your published config:

'routes' => [
    'admin' => [
        'middleware' => ['web', 'admin'],
    ],
],

License

MIT. See LICENSE.