Download the PHP package niclasleonbock/eloquent-activatable without Composer
On this page you can find all versions of the php package niclasleonbock/eloquent-activatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download niclasleonbock/eloquent-activatable
More information about niclasleonbock/eloquent-activatable
Files in niclasleonbock/eloquent-activatable
Package eloquent-activatable
Short Description Creating (de-) activatable Eloquent Models made easy.
License MIT
Informations about the package eloquent-activatable
Eloquent Activatable
Creating (de-) activatable Eloquent Models made easy.
Installation
First, you'll need to add the package to your composer.json
and run composer update
.
Please require version 4.0 when using with Laravel 4.x.
Now, simply add a datetime column called activated_at
to your table and use the ActivatableTrait
(niclasleonbock\Eloquent\ActivatableTrait
) in your Eloquent model.
Migration
Your Model
And you're done!
Use
withDeactivated()
By default all database queries will be filtered so that only activated data sets are shown. To also show deactivated data sets you may use the withDeactivated
method on the query builder.
onlyDeactivated()
To get only deactivated data sets use the onlyDeactivated
method.
activated()
To check whether a data set is deactivated you may use the activated
method.
activate()
To activate a data set use the activate
method.
deactivate()
To deactivate a data set use the deactivate
method.
Customization
Sometimes the column name activated_at
may not fit even though the functionality does. To change the name you can easily override the protected $activatedAtColumn
variable or the public getActivatedAtColumn
method.