bakkali / laravel-media
Simple polymorphic media library for Laravel
Installs: 41
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bakkali/laravel-media
Requires
- php: ^8.1
- illuminate/support: ^11.0|^12.0
README
Simple, lightweight polymorphic media library for Laravel.
Attach, retrieve, and manage media files (images, documents, etc.) on any Eloquent model.
🛠 Created by Yusuf Bakkali
✨ Features
- Polymorphic relation: attach media to any Eloquent model
- Custom collection names (e.g., 'gallery', 'cover')
- JSON fields for flexible metadata
- Easily add / get / remove media files
- Designed to be simple & extendable
⚡ Installation
1️⃣ Require the package
composer require bakkali/laravel-media:dev-main
2️⃣ Publish migration & migrate
php artisan vendor:publish --tag=media-migrations php artisan migrate
🧩 Usage
use Bakkali\Media\Traits\HasMedia; class Post extends Model { use HasMedia; // your code... }
📥 Add media to a model
$post = Post::find(1); // Add a media file to 'images' collection $post->addMedia('/path/to/file.jpg', 'images');
📂 Get media by collection
$images = $post->getMedia('images'); foreach ($images as $media) { echo $media->file_name; echo $media->disk; }
✏ Update media attributes
$post->updateMedia($mediaId, [ 'name' => 'New name' ]);
🧹 Soft delete media (alias)
$post->destroyMedia($mediaId);
❌ Permanently delete media
$post->forceDeleteMedia($mediaId);
🛠 Development & Updates
- composer update bakkali/laravel-media:dev-main