hnhdigital-os / laravel-model-traits
Provides a collection of useful traits for Laravel Eloquent models.
1.0.12
2018-10-21 12:20 UTC
Requires
- php: >=7.0
- hnhdigital-os/laravel-helper-collection: ~1.0
- hnhdigital-os/laravel-null-carbon: ~1.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- illuminate/database: 4.*|5.*
- phpunit/phpunit: 4.*
- symfony/process: ~2.3
README
Provides a collection of useful traits for Laravel Eloquent models.
This package has been developed by H&H|Digital, an Australian botique developer. Visit us at hnh.digital.
Install
Via composer:
$ composer require hnhdigital-os/laravel-model-traits ~1.0
Usage
Model saving
Add or save a model with model based attribute rules.
use Bluora\LarvelModelTraits\ModelValidationTrait; class User extends Model { use ModelValidationTrait; }
Model events
Automatically call an event for created and updated on a model.
use Bluora\LarvelModelTraits\ModelEventsTrait; class User extends Model { use ModelEventsTrait; }
OrderBy
Adds
- Model default ordering
- Relation based ordering
- Supports raw input.
use Bluora\LarvelModelTraits\OrderByTrait; class User extends Model { use OrderByTrait; protected $default_order_by = 'name'; protected $default_order_direction = 'asc'; }
$model->order('FIELD(status,3,2,1)', 'desc');
$model->order('other_model.status', 'desc');
Model state (Active, Archived, Deleted) Support
Adds support for functions relating to the state of a model provided by the Eloquent ORM.
The feature is exposed through a trait by casting your UUID columns as uuid
.
use Bluora\LarvelModelTraits\ModelStateTrait; class User extends Model { use ModelStateTrait; }
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.