Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Comparing laravel-mediable with laravel-medialibrary

Link –

Laravel-Mediable is a package to upload and handle all sorts of files (aka media) in a Laravel app. It was built by a Canadian based web agency called Plank.

With it you can do things like this:

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

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

Pretty cool. You can read more on the way and how the package was built in an introductory post on the Plank blog.

At Spatie we've also built our own solution for handling media. In Plank's blogpost Sean lists these differences between their package and our Medialibrary.

spatie/laravel-medialibrary plank/laravel-mediable
Relationship many-to-one polymorphic, each media record is owned by one related model many-to-many polymorphic, each media record can connect to any number of related models, and vice versa.
Filesystem Files are stored in directories named after the media id relative to the disk root Files can be stored anywhere on the disk
Association Identifier Each media record belongs to one "collection" Media can be attached to a model with any number of "tags"
Aggregate Types Support for images and pdfs Configurable support for any number of custom types
Miscellaneous Features Glide manipulations Synchronization commands

Since our medialibary was introduced I've been asked from time to time why our medialibrary uses a many-to-one polymorphic relationship. The answer is: simplicity.

A previous iteration of our Blender CMS (a version that used Zend Framework 1 instead of Laravel ?) had a screen where the user could pick a file from all uploaded files (it looked much like this wordpress screen). We saw that, after having set up a lot of sites with Blender, that almost none of our clients used that screen...

In our projects we also see that our clients mostly need to attach an image, or a pdf or whatever, ... to only one model (for instance a news item). It rarely happens that a client wants to attach the same file to different models.

In our code we want to handle that use case as simple as possible and that's why we preferred using a many-to-one relation over a many-to-many relation. All the other differences listed in Plank's post are caused by the same reasoning, we preferred simplicity and ease of use over flexibility.

If you're looking for a good solution to handle media in a Laravel app I suggest you take a look at both our Medialibrary and Plank's Mediable package. Both packages are good at what they do. Pick the one that best fits your project (and just feels good to you).

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.


What are your thoughts on "Comparing laravel-mediable with laravel-medialibrary"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.