Download the PHP package waavi/laravel-value-objects without Composer

On this page you can find all versions of the php package waavi/laravel-value-objects. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-value-objects

Value Objects for Laravel 5

Latest Version on Packagist Build Status Total Downloads

Allows you to create value objects in Eloquent Models that are then saved into the database as either plain strings or json encoded.

WAAVI is a web development studio based in Madrid, Spain. You can learn more about us at waavi.com

Installation

You may install the package via composer

composer require waavi/laravel-value-objects 1.0.x

Usage

Using single field value objects

Say you wish to add an Temperature field to a Device eloquent model. You may wish to apply transformations to this field, or get the value in Celsius, Fahrenheit or Kelvin. If you use this type of field in several models, it might become cumbersome to copy paste these functions between all models.

Here is were value objects become very useful. Let's see how. First we created the Device model, which will have a temperature field cast to the Temperature value object and will use the 'CastsValueObjects' trait.

The Temperature value object will extend from 'Waavi\ValueObjects\Single' and could be defined as follows:

Single field value objects are saved as plain string in the database, and can be uses as follows:

You may also use Accessors and Mutators, just like in Eloquent Models. For example you could rewrite the Temperature class as:

You could then access the temperature properties as follows:

Using multiple fields value objects

Sometimes are value objects might not be so simple, and might require several fields instead of just one. Let's say we have a Trip model with origin and destination fields made up of coordinates. We could then define the Trip model like we did before:

We would then be able to define the Coordinate value object like:

Now we need to extend from the 'Waavi\ValueObjects\Json' Value Object, since we will need several fields to represent our Value Object, and we will need to define a fillable array with the names of the fields that are allowed in the value object. This time, the field will be json encoded before being saved.

As before, mutators and accessors are available.

We can work with this model object like so:


All versions of laravel-value-objects with dependencies

PHP Build Version
Package Version
Requires illuminate/support Version 5.1.x
illuminate/cache Version 5.1.x
illuminate/http Version 5.1.x
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package waavi/laravel-value-objects contains the following files

Loading the files please wait ....