bozboz/media-library

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v0.4.4) of this package.

v0.4.4 2015-07-21 16:15 UTC

README

Overview

This package provides the ability to relate a piece of Media to any model via a polymorphic join table. Once correctly configured, create/edit views for the affected models will render the MediaBrowser field. The MediaBrowser field simply presents the user with existing Media to mark as being related.

Installation

  1. Add bozboz/media-library to composer.json:
	"require": {
		"bozboz/media-library": "0.2.*"
	}
  1. Add the following to the providers array within app/config/app.php:
	'Bozboz\MediaLibrary\MediaLibraryServiceProvider',
	'Thapp\JitImage\JitImageServiceProvider'
  1. Publish bozboz/media-library assets, migratons and configuration:
	./artisan config:publish bozboz/media-library
	./artisan asset:publish bozboz/media-library
	./artisan migrate:publish bozboz/media-library
  1. Run ./artisan migrate

  2. Run ./artisan asset:publish bozboz/media-library

  3. Run gulp

  4. Run ./artisan config:publish thapp/jitimage

  5. Open app/config/packages/thapp/jitimage/config.php and update with the following:

	use Bozboz\MediaLibrary\ImageFilters\Resize;
	use Bozboz\MediaLibrary\ImageFilters\ResizeAndCrop;

	return [
		...
		'recipes' => [
			'library' => new Resize(150, 0),
			'thumb' => new ResizeAndCrop(150, 150)
		]
	];

Making models "mediable"

By default, only Pages will be mediable out of the box. You can define new media models inside app/config/packages/bozboz/media-library/config.php:

	'models' => [
		'Bozboz\Admin\Models\Page'
	]

General information

This works by listening out for when a create/edit form is being built by using the MediaEventHandler subscriber. If the form being rendered is associated with a mediable model, a select box containing available Media is displayed to the user.

To get all Media instances for a given Page model, pass the Page model to Media::forModel(). This will return an instancce of Illuminate\Database\Eloquent\Relations\MorphToMany which contains the results. Actual model instances can be accessed by calling get() on the return value.