2017 © Pedro Peláez
 

laravel-package media-manager

Provides a model around the storage, gives you image styles and a admin to manage your media

image

laravel-admin/media-manager

Provides a model around the storage, gives you image styles and a admin to manage your media

  • Tuesday, July 3, 2018
  • by marcoboom
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1,090 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 25 Versions
  • 7 % Grown

The README.md

Laravel-Media-Manager

This package has 4 main goals: * Provide an Eloquent model around your applications storage * By implementing a trait on your models automaticly create a 1-n relation with the media model * Create image styles for images and store or cache these * Provide a Vue component to show and browse for media, (*1)

Note: This package is still under development. Using it on productions environments is on your own risk. Collaborations and tips are always welcome, (*2)

Requirements

This package is completely build on the philosofy of Laravel 5.3. It uses the 5.3 method to quickly upload files and a Vue components setup as in Laravel Elixir 6. Do not use this package for Laravel 5.2 or lower. The templates of the Vue components are completly build on Bootstrap 3., (*3)

Installation

Require this package with Composer, (*4)

composer require laravel-admin/media-manager

Add the ServiceProvider to the providers array in app/config/app.php, (*5)

LaravelAdmin\MediaManager\MediaManagerProvider::class

If you want to edit the config or backend views you need to publish these resources to your application, (*6)

php artisan vendor:publish

The package generates a migration file for the media model, so migrate your database to create the table., (*7)

php artisan migrate

To use the Vue components in your (admin) applications, require the javascript bootstrap file from your vendor folder in your app.js file., (*8)

require('../../../vendor/laravel-admin/media-manager/resources/js/bootstrap.js');

Note: The javascript requires Dropzone to work, use the following statement to install it:, (*9)

npm install dropzone --save-dev

Upload media

With the following code you can upload a file to your default storage and returns the created media model., (*10)

use LaravelAdmin\MediaManager\Upload;

$media = Upload::handle($request, 'file');

Note: the first parameter of the handle method is the default Laravel Request object. The second parameter is the name of the submitted file., (*11)

It's possible to upload a file to another storage. This storage has to be a configured storage as in config/filesystems.php, (*12)

$media = Upload::storage('s3')->handle($request, 'file');

Note: The Eloquent model saves the storage in the database, so your application always knows where to find the uploaded file., (*13)

The Uploader uses a driver based system to add files to your storage and database. You can create your own drivers and add it to the media config, within upload/drivers. Your driver has to implement the following interface:, (*14)

LaravelAdmin\Mediamanager\Contracts\UploadDriver

By default the package provides two drivers. The default for uploading files from your request and a second one 'url' to directly save files from an url. To change the driver, just do:, (*15)

$media = Upload::with('url')->handle($request, 'http://domain.com/somefile.jpg');

You can also replace an existing model instead of create a new one., (*16)

$media = Upload::update($current_model)->handle($request, 'file');

Create a relation

If you want to create a relation between your model and the media model, you can do this simple to add a field to your table and add the MediaTrait to your model., (*17)

Create a migration and add the following:, (*18)

$table->integer('media_id')->unsigned()->nullable();
$table->foreign('media_id')->references('id')->on('media')->onDelete('set null');

Note: add ->after('fieldname') to add the field at the position you want., (*19)

Now add the MediaTrait to your model, (*20)


namespace App; use Illuminate\Database\Eloquent\Model; use LaravelAdmin\MediaManager\Traits\MediaTrait; class Blog extends Model { use MediaTrait;

The trait is based on the convention that the field you add in your database is called 'media_id'. If you prefer another naming, or you have more than one field like a header, just add a relation manually to your model:, (*21)

public function myfieldname()
{
    return $this->belongsTo(\LaravelAdmin\MediaManager\Models\Media::class);
}

Now the trait is integrated, for now there are two new methods available on your model, (*22)

  • mediaUrl
  • imagestyle

mediaUrl

The mediaUrl method directly returns the public url of the connected media on your model, (*23)

$blog->mediaUrl();

Note: As parameter it is possible to send a custom media field., (*24)

imagestyle

The imagestyle receives the imagestyle you want and return directly the url of the style. As second parameter you can pass a custom relation instead of 'media'., (*25)

$blog->imagestyle('thumbnail');

The Versions

03/07 2018

dev-master

9999999-dev

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

03/07 2018

dev-develop

dev-develop

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

03/07 2018

dev-release/3.0.11

dev-release/3.0.11

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

03/07 2018

3.0.11

3.0.11.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

15/02 2018

dev-release/3.0.10

dev-release/3.0.10

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

15/02 2018

3.0.10

3.0.10.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

14/02 2018

3.0.9

3.0.9.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

09/02 2018

dev-bug/catch-non-existent-image

dev-bug/catch-non-existent-image

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

18/08 2017

3.0.8

3.0.8.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

02/08 2017

v3.0.7

3.0.7.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

29/05 2017

3.0.6

3.0.6.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

29/05 2017

3.0.5

3.0.5.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

26/05 2017

3.0.4

3.0.4.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

28/01 2017

3.0.3

3.0.3.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

28/01 2017

3.0.2

3.0.2.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

28/01 2017

3.0.1

3.0.1.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

27/01 2017

3.0.0

3.0.0.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

16/12 2016

2.0.1

2.0.1.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

16/12 2016

2.0.0

2.0.0.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

30/09 2016

1.1.0

1.1.0.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

30/09 2016

1.0.5

1.0.5.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

30/09 2016

1.0.4

1.0.4.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

18/09 2016

1.0.3

1.0.3.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

18/09 2016

1.0.1

1.0.1.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom

18/09 2016

1.0.0

1.0.0.0

Provides a model around the storage, gives you image styles and a admin to manage your media

  Sources   Download

MIT

The Requires

 

by Marco boom