2017 © Pedro Peláez
 

library media

Laravel package for saving uploaded files and linking them with models

image

devfactory/media

Laravel package for saving uploaded files and linking them with models

  • Thursday, January 12, 2017
  • by devfactory
  • Repository
  • 6 Watchers
  • 18 Stars
  • 8,451 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 25 Versions
  • 3 % Grown

The README.md

Media

This package saves uploaded files and links them with models, (*1)

Installation

Laravel 5

NOTE: If upgrading from 2.0.0, run php artisan vendor:publish and php artisan migrate, (*2)

Using Composer, edit your composer.json file to require devfactory/media., (*3)

"require": {
  "devfactory/media": "2.0.*"
}

Then from the terminal run, (*4)

composer update

Then in your app/config/app.php file register the service providers:, (*5)

'Devfactory\Media\MediaServiceProvider',
'That0n3guy\Transliteration\TransliterationServiceProvider',

From within the laravel folder of your project, run:, (*6)

php artisan vendor:publish

Followed by:, (*7)

php artisan migrate

Laravel 4

Using Composer, edit your composer.json file to require devfactory/media., (*8)

"require": {
  "devfactory/media": "1.0.*"
}

Then from the terminal run, (*9)

composer update

Then in your app/config/app.php file register the service providers:, (*10)

'Devfactory\Media\MediaServiceProvider',
'That0n3guy\Transliteration\TransliterationServiceProvider',

Run the migration to create the DB table:, (*11)

php artisan migrate --package=devfactory/media

Finally, publish the config to make changes to where and how the files are stored:, (*12)

php artisan config:publish devfactory/media

Usage

To use the package, you need to add the following to any of your models which will be receiving media uploads., (*13)

<?php

class User extends Eloquent {

  use \Devfactory\Media\MediaTrait;

);

Then to save a media, in the method that handles your form submission you just need to pass the File object to saveMedia():, (*14)

public function upload() {
  $user = User::firstOrCreate(['id' => 1]);

  if (Input::hasFile('image')) {
    $user->saveMedia(Input::file('image'));
  }

  return Redirect::route('route');
}

This will create the file on the file system and insert an entry into the DB table media., (*15)

If you need to set multiple different types of images on a Model, like the users' profile picture and a background for their page you can use the second parameter:, (*16)

$user->saveMedia(Input::file('profile_picture'), 'profile_picture');
$user->saveMedia(Input::file('background_image'), 'background_image');

To retrieve the images again, you just need to call getMedia():, (*17)

// Retrieves every Media linked with the user
$all_media = $user->getMedia();

// Retrieve a specific Media
$profile_picture = $user->getMedia('profile_picture');

Finally you can delete media with deleteMedia():, (*18)

// Delete all media for a user
$user->deleteMedia();

// Delete specific media
$user->deleteMedia('profile_picture');

The Versions

12/01 2017

2.0.x-dev

2.0.9999999.9999999-dev

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

12/01 2017

dev-master

9999999-dev

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

12/01 2017

2.0.8

2.0.8.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

05/11 2015

1.0.x-dev

1.0.9999999.9999999-dev

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

02/10 2015

1.0.13

1.0.13.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

15/09 2015

2.0.7

2.0.7.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

27/08 2015

2.0.6

2.0.6.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

14/08 2015

2.0.5

2.0.5.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

29/07 2015

2.0.4

2.0.4.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

15/06 2015

2.0.3

2.0.3.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

12/05 2015

1.0.12

1.0.12.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

04/05 2015

1.0.11

1.0.11.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

04/05 2015

1.0.10

1.0.10.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

24/04 2015

1.0.9

1.0.9.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

07/04 2015

2.0.2

2.0.2.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

07/04 2015

1.0.8

1.0.8.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

26/03 2015

2.0.1

2.0.1.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

12/02 2015

2.0.0

2.0.0.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

16/01 2015

1.0.7

1.0.7.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

02/12 2014

1.0.6

1.0.6.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

02/12 2014

1.0.5

1.0.5.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

02/12 2014

1.0.3

1.0.3.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

25/11 2014

1.0.2

1.0.2.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

25/11 2014

1.0.1

1.0.1.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl

24/11 2014

1.0.0

1.0.0.0

Laravel package for saving uploaded files and linking them with models

  Sources   Download

MIT

The Requires

 

by DevFactory Sarl