echowine / laravel-orm-ao
There is no license information available for the latest version (dev-master) of this package.
dev-master
2017-02-10 23:59 UTC
Requires
- danielstjules/stringy: ^2.3
This package is not auto-updated.
Last update: 2025-01-27 17:17:48 UTC
README
Treat your attributes as they deserve, as objects!
Installation
Modify your composer.json and run composer update
{ "require": { "echowine/laravel-orm-ao":"@dev" } }
Defining a Model
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)
$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
###Exceptions
String
Thanks to magic methods editing the value of an attribute remains the same
$user = User::first(); $user -> username = "Admin"; $user -> save();
But i told you, attributes are objects!
$user -> username -> toLowerCase(); // "admin" $user -> username -> length(); // 5
###Methods
###Exceptions
The string field is currently using Stringy\Stringy, check all methods available here danielstjules/Stringy