PHPackages                             turahe/media - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. turahe/media

ActiveLibrary[File &amp; Storage](/categories/file-storage)

turahe/media
============

Associate files with Eloquent models

v3.0.0(9mo ago)02691MITPHPPHP ^8.4CI failing

Since Jul 4Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/turahe/media)[ Packagist](https://packagist.org/packages/turahe/media)[ RSS](/packages/turahe-media/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (10)Used By (1)

Laravel Media
=============

[](#laravel-media)

[![Tests](https://github.com/turahe/media/actions/workflows/run-tests.yml/badge.svg)](https://github.com/turahe/media/actions)[![Coverage Status](https://camo.githubusercontent.com/a48152385165001d063f77e2a49974e2c2690bc452d931aeabcdbef9f71b8acc/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7475726168652f6d656469613f7374796c653d666c61742d737175617265)](https://codecov.io/gh/turahe/media)[![PHP Version](https://camo.githubusercontent.com/f6a99b9e7a215983fb926bee3691218da5cdc6689fc0925d39d5896da74da640/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7475726168652f6d656469613f7374796c653d666c61742d737175617265)](https://packagist.org/packages/turahe/media)[![StyleCI](https://camo.githubusercontent.com/afb73876e63561a031c959b20304afb55839a7b8678cb9ea2a94e1e9e876c0a2/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3138353030303030302f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/185000000)[![Latest Stable Version](https://camo.githubusercontent.com/8be838eca2c9517831ae12755268086e797c69a72bd5b466c665f4b174b6696f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7475726168652f6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/turahe/media)[![Total Downloads](https://camo.githubusercontent.com/ef567403d999c61895cf5d5f0d2491e68ccb6e8ac5fd9dff2f894f201b151e2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7475726168652f6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/turahe/media)[![License](https://camo.githubusercontent.com/127aab9698dce2ba40242f6ebb9aeb155ab660725490c971d78722ac296366bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7475726168652f6d656469612e7376673f7374796c653d666c61742d737175617265)](LICENSE)

An easy solution to attach files to your Eloquent models, with image manipulation built in!

---

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Key Concepts](#key-concepts)
- [Uploading Media](#uploading-media)
    - [From Uploaded File](#from-uploaded-file)
    - [From URL](#from-url)
    - [From Base64 String](#from-base64-string)
    - [Customizing Uploads](#customizing-uploads)
- [Associating Media with Models](#associating-media-with-models)
- [Disassociating &amp; Deleting Media](#disassociating--deleting-media)
- [Retrieving Media](#retrieving-media)
- [Image Manipulation &amp; Conversions](#image-manipulation--conversions)

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require turahe/media
```

Publish the assets to create the necessary migration and config files:

```
php artisan vendor:publish --provider="Turahe\Media\MediaServiceProvider"
```

---

Key Concepts
------------

[](#key-concepts)

- **Media** can be any file type (image, document, etc). Restrict file types in your own validation logic.
- **Media** is uploaded as its own entity and can be managed independently.
- **Associations**: Media must be attached to a model to be related.
- **Groups**: Media items are bound to "groups" (e.g., images, documents) for flexible associations.
- **Conversions**: You can define image conversions (e.g., thumbnails) to be performed when media is attached.
- **Global Conversions**: Conversions are registered globally and reusable across models.

---

Uploading Media
---------------

[](#uploading-media)

Use the `Turahe\Media\MediaUploader` class to handle file uploads. By default, files are saved to the disk specified in your media config, with a sanitized file name, and a media record is created in the database.

### From Uploaded File

[](#from-uploaded-file)

```
$file = $request->file('file');

// Default usage
$media = MediaUploader::fromFile($file)->upload();
```

### Customizing Uploads

[](#customizing-uploads)

You can customize the file name and media name before uploading:

```
$media = MediaUploader::fromFile($file)
    ->useFileName('custom-file-name.jpeg')
    ->useName('Custom media name')
    ->upload();
```

### From URL

[](#from-url)

Upload media directly from a remote URL:

```
$media = MediaUploader::fromUrl('https://example.com/image.jpg')->upload();
```

### From Base64 String

[](#from-base64-string)

Upload media from a base64-encoded string (with or without a data URI prefix):

```
$base64 = '...'; // your base64 string
$media = MediaUploader::fromBase64($base64, 'image.png')->upload();
```

---

Associating Media with Models
-----------------------------

[](#associating-media-with-models)

To associate media with a model, include the `Turahe\Media\HasMedia` trait:

```
class Post extends Model
{
    use HasMedia;
}
```

Attach media to a model:

```
$post = Post::first();

// To the default group
$post->attachMedia($media);

// To a custom group
$post->attachMedia($media, 'custom-group');
```

---

Disassociating &amp; Deleting Media
-----------------------------------

[](#disassociating--deleting-media)

Detach media from a model:

```
// Detach all media
$post->detachMedia();

// Detach specific media
$post->detachMedia($media);

// Detach all media in a group
$post->clearMediaGroup('your-group');
```

Delete a media item (removes file and associations):

```
Media::first()->delete();
```

---

Retrieving Media
----------------

[](#retrieving-media)

Retrieve media attached to a model:

```
// All media in the default group
$post->getMedia();

// All media in a custom group
$post->getMedia('custom-group');

// First media item in the default group
$post->getFirstMedia();

// First media item in a custom group
$post->getFirstMedia('custom-group');
```

Get URLs for media:

```
// URL of the first media item in the default group
$post->getFirstMediaUrl();

// URL of the first media item in a custom group
$post->getFirstMediaUrl('custom-group');
```

---

Image Manipulation &amp; Conversions
------------------------------------

[](#image-manipulation--conversions)

You can define image conversions (e.g., thumbnails) using the familiar `intervention/image` library. Register conversions in a service provider:

```
use Intervention\Image\Image;
use Turahe\Media\Facades\Conversion;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Conversion::register('thumb', function (Image $image) {
            return $image->fit(64, 64);
        });
    }
}
```

Configure a media group to perform conversions:

```
class Post extends Model
{
    use HasMedia;

    public function registerMediaGroups()
    {
        $this->addMediaGroup('gallery')
             ->performConversions('thumb');
    }
}
```

Get the URL of a converted image:

```
// The thumbnail of the first image in the gallery group
$post->getFirstMediaUrl('gallery', 'thumb');
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance58

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Recently: every ~83 days

Total

9

Last Release

277d ago

Major Versions

v0.0.1 → v1.0.02022-07-16

v1.4 → v2.0.02025-07-19

v2.0.0 → v3.0.02025-08-09

PHP version history (6 changes)v0.0.1PHP ^7.4|^8.0

v1.0.0PHP ^8.0

v1.0.2PHP ^8.1

v1.0.3PHP ^8.3

v1.1.0PHP ^8.2

v3.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/f3513bd6100438bcb8c6b1a7e241a66e1ddaf1c11ee33883e06ef4a2784120db?d=identicon)[turahe](/maintainers/turahe)

---

Top Contributors

[![turahe](https://avatars.githubusercontent.com/u/6832622?v=4)](https://github.com/turahe "turahe (19 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/turahe-media/health.svg)

```
[![Health](https://phpackages.com/badges/turahe-media/health.svg)](https://phpackages.com/packages/turahe-media)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k511.3M2.2k](/packages/aws-aws-sdk-php)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[stechstudio/laravel-zipstream

A fast and simple streaming zip file downloader for Laravel.

4633.7M3](/packages/stechstudio-laravel-zipstream)[fof/upload

The file upload extension for the Flarum forum with insane intelligence.

188171.7k15](/packages/fof-upload)[uploadcare/uploadcare-php

Uploadcare PHP integration handles uploads and further operations with files by wrapping Upload and REST APIs.

1022.5M6](/packages/uploadcare-uploadcare-php)[azure-oss/storage

Azure Blob Storage PHP SDK

37985.0k5](/packages/azure-oss-storage)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
