PHPackages                             6reduk/eloquent-image-mutator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. 6reduk/eloquent-image-mutator

ActiveLibrary[File &amp; Storage](/categories/file-storage)

6reduk/eloquent-image-mutator
=============================

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

v2.1.10(10y ago)157Sahu Soft India Private LimitedPHPPHP &gt;=5.5.9

Since Aug 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/6reduk/eloquent-image-mutator)[ Packagist](https://packagist.org/packages/6reduk/eloquent-image-mutator)[ Docs](https://github.com/6reduk/eloquent-image-mutator)[ RSS](/packages/6reduk-eloquent-image-mutator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (2)Versions (21)Used By (0)

Eloquent Image Mutator Version: 2^
==================================

[](#eloquent-image-mutator-version-2)

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.

Storing images with Model
-------------------------

[](#storing-images-with-model)

Upload using a form

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

```

OR

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

```
    $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

Copy already present Image Object

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

```

note:-

The `$user->photo_one` should be a added to `protected $image_fields`

And its model should `use EloquentImageMutatorTrait;`

Retrieving images with Model
----------------------------

[](#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

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

```

Eg (In blade file):-

```

```

Update Or Delete Images
-----------------------

[](#update-or-delete-images)

If you update a field with a new image the old image is deleted from the system.

OR

If you delete a record from a the table the image is deleted.

Installation
------------

[](#installation)

Add the following line to the `require` section of `composer.json`:

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

Setup
-----

[](#setup)

1. In `/config/app.php`, add the following to `providers`:

```
SahusoftCom\EloquentImageMutator\EloquentImageMutatorProvider::class,

```

2. Run `php artisan vendor:publish`.
3. In `/config/image.php`, you will have the default target folder.

    ```
    storage/app/uploads

    ```

    If you want to use this detination as the upload folder, Do make the directories required i.e., `storage/app/uploads`.
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

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

    ```

How to use
----------

[](#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:

```
```
