定制 jenssegers/model 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jenssegers/model

最新稳定版本:v1.5.4

Composer 安装命令:

composer require jenssegers/model

包简介

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

README 文档

README

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

统计信息

  • 总下载量: 4.11M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 397
  • 点击次数: 2
  • 依赖项目数: 34
  • 推荐数: 0

GitHub 信息

  • Stars: 396
  • Watchers: 8
  • Forks: 56
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04