rawbinn / media
Media library for Laravel — uploads, storage, image variants, and file manager.
Requires
- php: ^8.3
- illuminate/config: ^13.0
- illuminate/database: ^13.0
- illuminate/filesystem: ^13.0
- illuminate/http: ^13.0
- illuminate/routing: ^13.0
- illuminate/support: ^13.0
- intervention/image: ^3.0
Requires (Dev)
- orchestra/testbench: ^11.0
- phpunit/phpunit: ^12.0
Suggests
- laravel/framework: Required for full Laravel integration.
Provides
None
Conflicts
None
Replaces
None
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/uploadGET admin/filemanager/filesGET 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.