sfneal / models
Eloquent Model wrapper with extended functionality
Installs: 85 805
Dependents: 9
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- laravel/framework: ^9.0|^10.0|^11.0
- sfneal/actions: ^2.0
- sfneal/laravel-helpers: ^2.0
- sfneal/redis-helpers: ^1.2|^2.0|^3.0
- sfneal/string-helpers: >=1.1.4
Requires (Dev)
- laravel/legacy-factories: >=1.1.0
- orchestra/testbench: ^8.0|9.0|^9.0
- phpunit/phpunit: ^10.0|^11.0
- sfneal/array-helpers: ^3.0
This package is auto-updated.
Last update: 2024-11-02 16:54:35 UTC
README
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.