Download the PHP package felipeweb11/laravel-easymutators without Composer
On this page you can find all versions of the php package felipeweb11/laravel-easymutators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download felipeweb11/laravel-easymutators
More information about felipeweb11/laravel-easymutators
Files in felipeweb11/laravel-easymutators
Package laravel-easymutators
Short Description Value object mutation solution for Laravel 5.
License MIT
Homepage https://github.com/felipeweb11/laravel-easymutators
Informations about the package laravel-easymutators
Value object mutation solution for Laravel 5.
This package provides an easy way to use Value Objects with your eloquent models. A set of mutations is included out of the box in this package, so you can easily upload an Image and/or a File as value object and save it on your eloquent model, and you can also use our Settings value object implementation to save or settings on database.
Here are a few short examples of what you can do:
It can handle your uploads directly like above or fetch directly from an URL:
And you can access them later like this:
Requirements
To create derived images GD should be installed on your server.
Installation
You can install this package via composer using this command:
Next, you must install the service provider:
You can publish the config-file with:
This is the contents of the published config file:
And finally you should add a disk to app/config/filesystems.php
. This would be a typical configuration:
Basic usage
Let's use the User class as an example. First you should create fields on your database. Using migrations, you can do this on your users table to create an profile_photo field which will be used to store the users profile photo.
Now you should use the EasyMutatorsTrait on your model and set the mutations fields:
Now you are ready to easily save an image like this:
Handling image conversions
The storage of the files is handled by Laravel's Filesystem, so you can use any filesystem you like. Additionally the package can create image conversions for an specific image. If you want do use this, you can configure image conversions simply by implementing the mapMedia() method on your model, like this:
And you can access them later like this:
Optionally you can set a custom base upload directory for your model, by default the base upload dir is formed by combination of short class name of the model + entity primary key (if exists) + short hash.
Implementing your own value objects
You can create your own value objects by implementing the Webeleven\EloquentValueObject\ValueObjectInterface
And to use, you can configure the attribute on your model:
Or you can configure an alias on easymutators.php config file:
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-easymutators with dependencies
laravel/framework Version ^5.1
intervention/image Version ^2.3
felipeweb11/eloquent-value-object Version ^1.1