承接 sfneal/models 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sfneal/models

最新稳定版本:4.1.0

Composer 安装命令:

composer require sfneal/models

包简介

Eloquent Model wrapper with extended functionality

README 文档

README

Packagist PHP support Latest Version on Packagist Build Status Quality Score Total Downloads

Eloquent Model wrapper with extended functionality.

Installation

You can install the package via composer:

composer require sfneal/models

Usage

Models

AbstractModel, AbstractPivot, & AbstractAuthenticatable can be used as parent classes the same way Eloquent's Model, Pivot & Authenticatable can be used. AbstractModel uses Sfneal\Builders\QueryBuilder as the default Eloquent Query Builder (see sfneal/builders.

class YourModel extends AbstractModel
{
    protected $table = 'your_model';
    protected $primaryKey = 'your_model_id';
    
    protected $fillable = [
        'your_model_id',
        //
    ];
} 

Models that extend the AbstractModel class will have access to a variety of public access to a variety of methods that extends many of Models existing functionality's.

  • 'Newness' - methods to detetmine if a Model is new (useful for apps with CMS) or how new a model is
  • 'Changed' - methods to check if a Model was recently created, updated, deleted or unchanged
// Create a new Model record
$model = YourModel::query()->create($data);

// returns true
$model->wasCreated();

// Update the Model
$model->update([
	'some_attribute' => 'blue'
]);	

// returns false
$model->wasCreated();

// returns true
$model->wasUpdated();

Builders

Add the custom QueryBuilder to any Eloquent model by overwriting the built-in newEloquentBuilder() & query() methods.

use Illuminate\Database\Eloquent\Builder;
use Sfneal\Builders\QueryBuilder;

class ExampleModel extends Model
{
    /**
     * Query Builder.
     *
     * @param $query
     * @return QueryBuilder
     */
    public function newEloquentBuilder($query)
    {
        return new QueryBuilder($query);
    }
    
    /**
     * Query Builder method for improved type hinting.
     *
     * @return QueryBuilder|Builder
     */
    public static function query()
    {
        return parent::query();
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email stephen.neal14@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.

统计信息

  • 总下载量: 97.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-13