Download the PHP package leko-team/laravel-active without Composer
On this page you can find all versions of the php package leko-team/laravel-active. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leko-team/laravel-active
More information about leko-team/laravel-active
Files in leko-team/laravel-active
Package laravel-active
Short Description Ready-made solution for active an entity with Eloquent models
License MIT
Informations about the package laravel-active
Ready-made solution for active an entity with Eloquent models
This package can activate entity with Eloquent models. It provides a simple API to work with.
Installation
The library can be installed via Composer:
Configuration
To be able active eloquent entities you need:
$table->boolean('is_active')->default(false)->index()->comment('Признак активности'); $table->timestamp('start_at')->nullable()->index()->comment('Временная метка начала активности'); $table->timestamp('end_at')->nullable()->index()->comment('Временная метка окончания активности');
- Add migration with columns:
is_active
,start_at
,end_at
- Or assign:
static::IS_ACTIVE
,static::START_AT
,static::END_AT
constant with the name of the column you want to use.
If you have existing records in your table you maybe want to update them.
- Add trait
ActivityTrait
to your model.
Examples
Base
To activate entity:
To deactivate entity:
Scopes
By default from active entity return only active records with next condition: Entity is true and start_at IS NULL OR <= then current timestamp ('2023-10-23 13:52:37') and end_at IS NULL OR end_at >= then current timestamp ('2023-10-23 13:52:37')
.
You can change this by applying scope to your Eloquent model.
- withInactive
Returns all records.
Credits
- A big thank you to Laravel Package for helping out build package with step by step guide.
- Oleg Kolzhanov for helping with logic.
License
The MIT License (MIT). Please see License File for more information.