2017 © Pedro Peláez
 

library eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

image

6reduk/eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

  • Tuesday, May 10, 2016
  • by 6reduk
  • Repository
  • 1 Watchers
  • 1 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 24 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

Relating an image with a model is always a pain. Eloquent Image Mutator provides an easy mutator for Eloquent models to save and retrieve images., (*1)

Storing images with Model

Upload using a form, (*2)

    $user->profile_picture = \Input::file('image');
    $user->save();

OR, (*3)

Upload using a public URL (We will download and store the image for you), (*4)

    $user->profile_picture = https://scontent.fbom1-2.fna.fbcdn.net/hprofile-xaf1/v/t1.0-1/p160x160/11659393_10207093577848521_887484828555984342_n.jpg?oh=089042c5f4afa05e0dcbde51130c0eea&oe=56689CB9;
    $user->save();

OR, (*5)

Copy already present Image Object, (*6)

    $user->profile_picture = $user->photo_one;
    $user->save();

note:-, (*7)

The $user->photo_one should be a added to protected $image_fields, (*8)

And its model should use EloquentImageMutatorTrait;, (*9)

Retrieving images with Model

     $user->profile_picture->thumbnail->url
     $user->profile_picture->xsmall->url
     $user->profile_picture->small->url
     $user->profile_picture->profile->url
     $user->profile_picture->medium->url
     $user->profile_picture->large->url
     $user->profile_picture->original->url

You can even access the height and width, (*10)

    $user->profile_picture->large->height
    $user->profile_picture->large->width

Eg (In blade file):-, (*11)

<img src="{{ $user->profile_picture->profile->url }}" />, (*12)

Update Or Delete Images

If you update a field with a new image the old image is deleted from the system., (*13)

OR, (*14)

If you delete a record from a the table the image is deleted., (*15)

Installation

Add the following line to the require section of composer.json:, (*16)

{
    "require": {
        "sahusoftcom/eloquent-image-mutator": "dev-master"
    }
}

Setup

  1. In /config/app.php, add the following to providers:, (*17)

    SahusoftCom\EloquentImageMutator\EloquentImageMutatorProvider::class,
    
  2. Run php artisan vendor:publish., (*18)

  3. In /config/image.php, you will have the default target folder., (*19)

    storage/app/uploads
    

    If you want to use this detination as the upload folder, Do make the directories required i.e., storage/app/uploads., (*20)

  4. In public folder you should have a soft-link pointing to the upload folder destination named uploads. You could do this by creating a soft link in public.Go to your projects public folder and, (*21)

    ln -s relative-path-to-destination-folder uploads
    

How to use

  1. The field against which you want to store the image should be of type text.
  2. You should use the EloquentImageMutatorTrait in the Model.
  3. Define the columns you want to inculde for image uploads.

For example:, (*22)

```
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SahusoftCom\EloquentImageMutator\EloquentImageMutatorTrait;

class User extends Model
{

    use EloquentImageMutatorTrait;

    /**
     * The photo fields should be listed here.
     *
     * @var array
     */
    protected $image_fields = ['profile_picture', 'cover_photo'];

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['profile_picture', 'cover_photo'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];
    .
    .
    .

}
```

And to then with the user object you can just use it like a property, (*23)

Example:, (*24)

Storing images with Model, (*25)

    $user->profile_picture = \Input::file('image');
    $user->save();

Retrieving images with Model, (*26)

     $user->profile_picture->thumbnail->url
     $user->profile_picture->xsmall->url
     $user->profile_picture->small->url
     $user->profile_picture->profile->url
     $user->profile_picture->medium->url
     $user->profile_picture->large->url
     $user->profile_picture->original->url

Thanks!, (*27)

Customization

You could customize the target folder where the images are stored. For customizing goto config/image.php. Line no 6, (*28)

'assets_upload_path' => 'storage/app/uploads',

and change the destination to your desired folder. Make sure the destination folder has all the permissions and the soft link in the public folder is pointing to the destionation folder., (*29)

====================================================, (*30)

Eloquent Image Mutator Version: 1.*

Relating an image with a model is always a pain. Eloquent Image Mutator provides an easy mutator for Eloquent models to save and retrieve images., (*31)

Storing images with Model

    $user->profile_picture = \Input::file('image');
    $user->save();

Retrieving images with Model

     $user->profile_picture->thumbnail
     $user->profile_picture->xsmall
     $user->profile_picture->small
     $user->profile_picture->profile
     $user->profile_picture->medium
     $user->profile_picture->large

Eg (In blade file):-, (*32)

<img src="{{ $user->profile_picture->profile }}" />, (*33)

Installation

Add the following line to the require section of composer.json:, (*34)

{
    "require": {
        "sahusoftcom/eloquent-image-mutator": "dev-master"
    }
}

Setup

  1. In /config/app.php, add the following to providers:, (*35)

    SahusoftCom\EloquentImageMutator\EloquentImageMutatorProvider::class,
    
  2. Run php artisan vendor:publish., (*36)

  3. In /config/image.php, you will have the default target folder., (*37)

    storage/app/uploads
    

    If you want to use this detination as the upload folder, Do make the directories required i.e., storage/app/uploads., (*38)

  4. In public folder you should have a soft-link pointing to the upload folder destination named uploads. You could do this by creating a soft link in public.Go to your projects public folder and, (*39)

    ln -s relative-path-to-destination-folder uploads
    

How to use

  1. The field against which you want to store the image should be of type text.
  2. You should use the EloquentImageMutatorTrait in the Model.
  3. Define the columns you want to inculde for image uploads.

For example:, (*40)

```
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SahusoftCom\EloquentImageMutator\EloquentImageMutatorTrait;

class User extends Model
{

    use EloquentImageMutatorTrait;

    /**
     * The photo fields should be listed here.
     *
     * @var array
     */
    protected $image_fields = ['profile_picture', 'cover_photo'];

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'image';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['profile_picture', 'cover_photo'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];
    .
    .
    .

}
```

And to then with the user object you can just use it like a property, (*41)

Example:, (*42)

Storing images with Model, (*43)

    $user->profile_picture = \Input::file('image');
    $user->save();

Retrieving images with Model, (*44)

     $user->profile_picture->thumbnail
     $user->profile_picture->xsmall
     $user->profile_picture->small
     $user->profile_picture->profile
     $user->profile_picture->medium
     $user->profile_picture->large

Thanks!, (*45)

Customization

You could customize the target folder where the images are stored. For customizing goto config/image.php. Line no 6, (*46)

'assets_upload_path' => 'storage/app/uploads',

and change the destination to your desired folder. Make sure the destination folder has all the permissions and the soft link in the public folder is pointing to the destionation folder., (*47)

The Versions

10/05 2016

dev-master

9999999-dev https://github.com/6reduk/eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank
by Dmitriy Shestakov

laravel upload image photo

10/05 2016

v2.1.10

2.1.10.0 https://github.com/6reduk/eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank
by Dmitriy Shestakov

laravel upload image photo

10/05 2016

v2.1.8

2.1.8.0 https://github.com/6reduk/eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank
by Dmitriy Shestakov

laravel upload image photo

10/05 2016

v2.1.9

2.1.9.0 https://github.com/6reduk/eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank
by Dmitriy Shestakov

laravel upload image photo

10/05 2016

dev-support_inherited_classes_for_uploaded_file_objects

dev-support_inherited_classes_for_uploaded_file_objects https://github.com/6reduk/eloquent-image-mutator

One solution for image uploads. Fork for https://github.com/sahusoftcom/eloquent-image-mutator

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank
by Dmitriy Shestakov

laravel upload image photo

14/03 2016

v2.1.7

2.1.7.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

07/12 2015

v2.1.6

2.1.6.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

02/11 2015

v2.1.5

2.1.5.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

02/10 2015

v2.1.4

2.1.4.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

24/09 2015

v2.1.3

2.1.3.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

22/09 2015

v2.1.2

2.1.2.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

22/09 2015

v2.1.1

2.1.1.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

04/09 2015

v2.1.0

2.1.0.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

28/08 2015

v2.0.3

2.0.3.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

26/08 2015

v2.0.2

2.0.2.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

26/08 2015

v2.0.1

2.0.1.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

26/08 2015

v2.0.0

2.0.0.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

20/08 2015

v1.1.1

1.1.1.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

15/08 2015

v1.1.0

1.1.0.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

14/08 2015

v1.0.1

1.0.1.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo

14/08 2015

v1.0.0

1.0.0.0 https://github.com/sahusoftcom/eloquent-image-mutator

One solution for image uploads.

  Sources   Download

Sahu Soft India Private Limited

The Requires

 

by Mrigank

laravel upload image photo