This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
Clone or download
jenssegers Merge pull request #20 from mauro-moreno/master
Added missing tests for addVisible, addHidden and casts
Latest commit eedaeed Jul 21, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Encode collection Jul 21, 2018
tests Encode collection Jul 21, 2018
.gitignore New version May 26, 2013
.travis.yml Relative path Jul 20, 2018 Update Dec 13, 2016
composer.json Rename repo Dec 11, 2015
phpunit.xml Add phpunit.xml Apr 27, 2014


Build Status Coverage Status

This model provides an Laravel eloquent-like base class that can be used to build custom models in Laravel or other frameworks.


  • 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 casting

You can read more about these features and the original Eloquent model on


Install using composer:

composer require jenssegers/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"}