bluora/laravel-model-traits

This package is abandoned and no longer maintained. The author suggests using the hnhdigital-os/laravel-model-traits package instead.

Provides a collection of useful traits for Laravel Eloquent models.

1.0.12 2018-10-21 12:20 UTC

This package is not auto-updated.

Last update: 2022-02-01 13:00:40 UTC


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.