The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Laravel Mediable

plank/laravel-mediable image

Laravel Mediable stats

Downloads
865.6K
Stars
692
Open Issues
11
Forks
92

View on GitHub →

A package for easily uploading and attaching media files to models with Laravel

Laravel-Mediable

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel.

Features

  • Filesystem-driven approach is easily configurable to allow any number of upload directories with different accessibility. Easily restrict uploads by MIME type, extension and/or aggregate type (e.g. image for JPEG, PNG or GIF).
  • Many-to-many polymorphic relationships allow any number of media to be assigned to any number of other models without any need to modify their schema.
  • Attach media to models with tags, in order to set and retrieve media for specific purposes, such as 'thumbnail', 'featured image', 'gallery' or 'download'.
  • Integrated support for integration/image for manipulating image files to create variants for different use cases.

Example Usage

Upload a file to the server, and place it in a directory on the filesystem disk named "uploads". This will create a Media record that can be used to refer to the file.

$media = MediaUploader::fromSource($request->file('thumb'))
->toDestination('uploads', 'blog/thumbnails')
->upload();

Attach the Media to another eloquent model with one or more tags defining their relationship.

$post = Post::create($this->request->input());
$post->attachMedia($media, ['thumbnail']);

Retrieve the media from the model by its tag(s).

$post->getMedia('thumbnail')->first()->getUrl();

Installation

Add the package to your Laravel app using composer

composer require plank/laravel-mediable

Register the package's service provider in config/app.php. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.

'providers' => [
...
Plank\Mediable\MediableServiceProvider::class,
...
];

The package comes with a Facade for the image uploader, which you can optionally register as well. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.

'aliases' => [
...
'MediaUploader' => Plank\Mediable\MediaUploaderFacade::class,
...
]

Publish the config file (config/mediable.php) of the package using artisan.

php artisan vendor:publish --provider="Plank\Mediable\MediableServiceProvider"

Run the migrations to add the required tables to your database.

php artisan migrate

Documentation

Read the documentation here.

License

This package is released under the MIT license (MIT).

About Plank

Plank is a web development agency based in Montreal, Canada.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Plank Laravel Mediable Related Articles

Verifying Exception Reporting in Laravel with assertReported image

Verifying Exception Reporting in Laravel with assertReported

Read article
Manage any Laravel app as if it was a CMS image

Manage any Laravel app as if it was a CMS

Read article
Website down? SSL invalid? You should use PingPing to get instantly notified! (sponsor) image

Website down? SSL invalid? You should use PingPing to get instantly notified! (sponsor)

Read article
Laravel Package Training (sponsor) image

Laravel Package Training (sponsor)

Read article
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum