New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

sertxudeveloper/laravel-media-model

Attach media files to your models
3,120 11

Larablocks Analysis

sertxudeveloper/laravel-media-model works with Laravel 10 and 11 (latest release v1.3.0, Mar 11, 2024), all past end of life (the last on Mar 12, 2026): no more fixes, even for security.

Laravel 9 in earlier releases.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • Supports only Laravel 10 and 11, past end of life since Mar 12, 2026
  • No release in the last 12 months (last: Mar 11, 2024)
  • 0 downloads a month (needs 10,000)
  • 11 GitHub stars (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Mar 11, 2024.
  • No releases in the last 12 months.
  • First released: Jun 2, 2022.
  • 1 open issue on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 28, 2026.

Install
composer require sertxudeveloper/laravel-media-model
Latest Version:v1.3.0
PHP:^8.1|^8.2
Laravel:10 · 11
Older releases:9
License:MIT
Last Updated:Oct 7, 2024
Links: GitHub  ·  Packagist
Maintainer: sertxudev

Laravel Media Model by Sertxu Developer

Attach media files to your models

Codecov Test coverage

When developing an app, you may want to attach media files to your models, such as images, videos, or documents. With this package, you can easily attach media files to your models.

The media files are stored in the specified disk and are related to the model using your database.

You can link local media files or remote ones without needing to download them to your server.

The main difference between this package and the other ones available is that this package allows you to relate media files to your models using a custom table per model.

Allowing you to manage the media tables per model instead of one unique media table for all models.

Installation

You can install the package via composer:

composer require sertxudeveloper/laravel-media-model

Next, you should publish the config file and the migrations:

php artisan vendor:publish --provider "SertxuDeveloper\Media\MediaServiceProvider"

After that, you can run the new migrations:

php artisan migrate

Finally, you can start using the package!

Usage

You should modify the model that you want to attach media files to.

<?php

namespace App\Models;

use SertxuDeveloper\Media\HasMedia;
use SertxuDeveloper\Media\Interfaces\MediaInteraction;

class Message extends Model implements MediaInteraction
{
    use HasMedia;
}

As you can see, the model has been modified to use the HasMedia trait. Also, the model must implement the MediaInteraction interface.

Separated media tables

If you want to use a separated media table for each model, you should modify the model that you want to attach media files to.

<?php

namespace App\Models;

use SertxuDeveloper\Media\HasMedia;
use SertxuDeveloper\Media\Interfaces\MediaInteraction;

class Message extends Model implements MediaInteraction
{
    use HasMedia;

    public function getMediaTable(): string
    {
        return 'messages_media';
    }
}

The specified table needs to be created, you can create it manually or use one of the following command.

php artisan media:create-table messages_media

or

php artisan media:create-table messages

or

php artisan media:create-table "App\Models\Message"

Attaching media files

Once you configured the model, you can attach media files to it. For example:

Note
If you don't specify a disk, the default disk will be used.

<?php

$message = Message::find(1);

$message->addMediaFromDisk(path: '/images/image.jpg', disk: 'public');

You can also attach a remote file:

Note
This will not download the file to your server. It will only add the remote file path to the database.

<?php

$message = Message::find(1);

$message->addMediaFromUrl('https://www.sertxudeveloper.com/assets/logo.svg');

Also, you can attach a file content, this will save the file to the disk and attach it to the model.

Note
This is useful if you get the content of a file from an external source, like as an email attachment read by a mail parser.

<?php

$message = Message::find(1);

$message->addMediaFromContent(
  content: file_get_contents('/tmp/tmpA3ds2'),
  originalName: 'image.jpg',
  toFolder: 'avatars',
  toDisk: 'public'
);

Testing

This package contains tests, you can run them using the following command:

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.



Copyright © 2022 Sertxu Developer

Related Packages

sertxudeveloper/laravel-lockscreen

Package for locking the user account due to inactivity

4,505 6
sertxudeveloper/livewire-combobox

Add combobox to your Livewire forms

3,323 5
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440

Version History

Version Released PHP Laravel License
v1.3.0 ^8.1|^8.2 ^10.0|^11.0 MIT
v1.2.0 ^8.1 ^9.5|^10.0 MIT
v1.1.0 ^8.1 ^9.5|^10.0 MIT
v1.0.1 ^8.1 ^9.5 MIT
v1.0.0 ^8.1 ^9.5 MIT
Pre-releases (1)
Version Released PHP Laravel License
v1.0.0-beta.1 ^8.1 ^9.0 MIT