2017 © Pedro Peláez
 

library laravel-orm-ao

image

echowine/laravel-orm-ao

  • Saturday, February 11, 2017
  • by echowine
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel ORM - Attribute as an Object

Treat your attributes as they deserve, as objects!, (*1)

Installation

Modify your composer.json and run composer update, (*2)

``` json { "require": { "echowine/laravel-orm-ao":"@dev" } }, (*3)


Defining a Model ------------ ```php namespace CoreWine\ORM\Test\Model; use CoreWine\ORM\Model; use CoreWine\ORM\AttributesBuilder; class User extends Model{ /** * The table associated with the model. * * @var string */ protected $table = 'tests_users'; /** * List of all your attributes. * * @param AttributesBuilder $builder * * @return void */ protected function attributes(AttributesBuilder $builder){ $builder -> string('username') -> minLength(3) -> maxLength(10) -> match("/^([a-zA-Z0-9])*$/"); $builder -> boolean('active'); $builder -> number('points') -> range(0,99); } }

Boolean

Starting with the easiest one, only two values accepted (true,false), (*4)

    $user = User::first();
    $user -> active = "true"; // true
    $user -> active = "false"; // false
    $user -> active = true; // true
    $user -> active = 1; // true

Number

    $user = User::first();
    $user -> points = 10;

Methods

Method Description
range(int $min, int $max) Minimum and maximum at once
min(int $min) Minimum value
max(int $max) Maximum value

Exceptions

Exception Description
CoreWine\ORM\Field\Number\Exceptions\TooSmallException The value is too small
CoreWine\ORM\Field\Number\Exceptions\TooBigException The value is too big

String

Thanks to magic methods editing the value of an attribute remains the same, (*5)

    $user = User::first();
    $user -> username = "Admin";
    $user -> save();

But i told you, attributes are objects!, (*6)

    $user -> username -> toLowerCase(); // "admin"
    $user -> username -> length(); // 5

Methods

Method Description
match(string\ closure $match) | A regular expression or a closure that define the correct value
minLength(int $min) Minimum length
maxLength(int $max) Maximum length

Exceptions

Exception Description
CoreWine\ORM\Field\Number\Exceptions\TooShortException The value is too short
CoreWine\ORM\Field\Number\Exceptions\TooLongException The value is too long
CoreWine\ORM\Field\Number\Exceptions\InvalidException The value doesn't match with the regex/closure

The string field is currently using Stringy\Stringy, check all methods available here danielstjules/Stringy, (*7)

The Versions

11/02 2017

dev-master

9999999-dev

  Sources   Download

The Requires