supportpal/eloquent-model

An Laravel eloquent-like model class, for Laravel and other frameworks
10,120
Install
composer require supportpal/eloquent-model
Latest Version:v1.1.0
Laravel:4 – 13
License:MIT
Last Updated:May 26, 2026
Links: GitHub  ·  Packagist
Maintainer: bytestream

Model

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.

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 casting

You can read more about these features and the original Eloquent model on http://laravel.com/docs/eloquent

Installation

Install using composer:

composer require jenssegers/model

Example


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"}

Related Packages

jenssegers/model

An Laravel eloquent-like model class, for Laravel and other frameworks

4,726,510 395
czim/laravel-nestedupdater

Eloquent model updater for nested relations data for Laravel.

54,026 19
cerbero/eloquent-inspector

Inspect Laravel Eloquent models to collect properties, relationships and more.

53,587 112
custom-d/eloquent-model-encrypt

A eloquent model encrypt

6,228
czim/laravel-modelcomparer

Performs a deep-nested comparison of a model's before/after state.

4,738 2

Version History

Version Released PHP Laravel License
v1.1.0 ^4.0|^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v1.0.0 ^8.1 ^10.0|^11.0 MIT