Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jenssegers/model
This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
https://github.com/jenssegers/model
Last synced: 5 days ago
JSON representation
This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
- Host: GitHub
- URL: https://github.com/jenssegers/model
- Owner: jenssegers
- Created: 2013-03-30T09:55:54.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T13:39:31.000Z (7 months ago)
- Last Synced: 2024-05-15T22:30:02.519Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 82 KB
- Stars: 354
- Watchers: 10
- Forks: 55
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Model
=====[![Build Status](http://img.shields.io/travis/jenssegers/model.svg)](https://travis-ci.org/jenssegers/model) [![Coverage Status](http://img.shields.io/coveralls/jenssegers/model.svg)](https://coveralls.io/r/jenssegers/model)
This model provides an Laravel eloquent-like base class that can be used to build custom models in Laravel or other frameworks.
Features
--------- Accessors and mutators
- Model to Array and JSON conversion
- Hidden attributes in Array/JSON conversion
- Guarded and fillable attributes
- Appending accessors and mutators to Array/JSON conversion
- Attribute castingYou can read more about these features and the original Eloquent model on http://laravel.com/docs/eloquent
Installation
------------Install using composer:
```bash
composer require jenssegers/model
```Example
-------```php
use Jenssegers\Model\Model;
class User extends Model {
protected $hidden = ['password'];
protected $guarded = ['password'];
protected $casts = ['age' => 'integer'];
public function save()
{
return API::post('/items', $this->attributes);
}public function setBirthdayAttribute($value)
{
$this->attributes['birthday'] = strtotime($value);
}public function getBirthdayAttribute($value)
{
return new DateTime("@$value");
}public function getAgeAttribute($value)
{
return $this->birthday->diff(new DateTime('now'))->y;
}
}$item = new User(array('name' => 'john'));
$item->password = 'bar';echo $item; // {"name":"john"}
```