• Stars
    star
    747
  • Rank 60,741 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Laravel-Mediable

Coveralls StyleCI Packagist

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.

More Repositories

1

laravel-metable

A package for handling arbitrary data in Laravel 5 applications
PHP
279
star
2

MarkerClusterer

A fork of the markerClusterer project at http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries
JavaScript
32
star
3

php-google-map-api

A fork of PHP Google Map API Class
PHP
19
star
4

secured

SSL Secure Component: Programmatically securing your controller actions.
PHP
16
star
5

pdfize

A CakePHP Plugin for PDF-ing output
10
star
6

laravel-checkpoint

A package for establishing a polymorphic many to many relationship between a model and a revisions table
PHP
7
star
7

larelations

Extract relations from Laravel Models
PHP
6
star
8

siren

Mermaid.js markdown generator for php
PHP
5
star
9

GeoKitPHP

A handy class used when dealing with MySQL and distance calculations.
PHP
5
star
10

laravel-media-manager

A Laravel package that exposes an API for handling media manipulations, and a set of Vue components to act as the interface for said API
JavaScript
4
star
11

authority

Authority: Simple static access control lists for the rest of us.
PHP
3
star
12

enumerable

An enumerable behavior wrapped in a plugin, for CakePHP listing needs.
PHP
3
star
13

csver

CakePHP Plugin for making CSVs. Simple, but works.
PHP
3
star
14

FrostedDocs-for-CakePHP

A better way to browse the CakePHP Book
PHP
2
star
15

yantra

A component-based state machine for restricting the user control flow graph.
PHP
1
star
16

wcmtl-api

Word Camp Montreal 2023. Plugin to demo custom API endpoints in WordPress.
PHP
1
star
17

Filemanager

Asset manager that has been customized to work with CakePHP
JavaScript
1
star
18

UIView-Layout-Extension

Objective-C
1
star
19

Seed-Framework

An inhouse PHP framework based on the principles of MVC
PHP
1
star
20

snapshots

Laravel content versioning scheme by versioning database tables
PHP
1
star