joemugen / eloquenty-model
A Laravel eloquent-like model class, for Laravel and other frameworks
Installs: 3 749
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0|^8.1
- ext-json: *
- illuminate/contracts: ^7.0|^8.0|^9.0
- illuminate/support: ^7.0|^8.0|^9.0
Requires (Dev)
- nunomaduro/phpinsights: ^v2.0
- orchestra/testbench: ^v6.23|^7.0
- pestphp/pest-plugin-faker: ^1.0
- pestphp/pest-plugin-global-assertions: ^1.0
- pestphp/pest-plugin-laravel: ^1.1
- pestphp/pest-plugin-parallel: ^0.3.1
- spatie/laravel-permission: ^5.5
This package is not auto-updated.
Last update: 2025-03-27 03:49:01 UTC
README
This model provides a 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 joemugen/eloquenty-model
Example
use JoeMugen\EloquentyModel\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(['name' => 'John']); $item->password = 'secret'; echo $item; // {"name":"John"}