2017 © Pedro Peláez
 

library eloquent-activatable

Creating (de-) activatable Eloquent Models made easy.

image

niclasleonbock/eloquent-activatable

Creating (de-) activatable Eloquent Models made easy.

  • Tuesday, July 18, 2017
  • by niclasleonbock
  • Repository
  • 1 Watchers
  • 7 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Eloquent Activatable

Creating (de-) activatable Eloquent Models made easy., (*1)

Build Status Scrutinizer Code Quality Code Coverage, (*2)

Installation

First, you'll need to add the package to your composer.json and run composer update., (*3)

{
    "require": {
        "niclasleonbock/eloquent-activatable": "~5.0"
    }
}

Please require version 4.0 when using with Laravel 4.x., (*4)

Now, simply add a datetime column called activated_at to your table and use the ActivatableTrait (niclasleonbock\Eloquent\ActivatableTrait) in your Eloquent model., (*5)

Migration

<?php
$table->datetime('activated_at')->nullable();

Your Model

<?php
use niclasleonbock\Eloquent\ActivatableTrait;

class Topic extends Eloquent
{
    use ActivatableTrait;

    // ...
}

And you're done!, (*6)

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., (*7)

<?php
$allTopics = Topic::withDeactivated()->get();

onlyDeactivated()

To get only deactivated data sets use the onlyDeactivated method., (*8)

<?php
$onlyDeactivatedTopics = Topic::onlyDeactivated()->get();

activated()

To check whether a data set is deactivated you may use the activated method., (*9)

<?php
echo 'My topic is ' . ($topic->activated() ? 'activated' : 'deactivated');

activate()

To activate a data set use the activate method., (*10)

<?php
$topic->activate();
$topic->save();

echo 'My topic is now ' . ($topic->activated() ? 'activated' : 'deactivated');

deactivate()

To deactivate a data set use the deactivate method., (*11)

<?php
$topic->deactivate();
$topic->save();

echo 'My topic is now ' . ($topic->activated() ? 'activated' : 'deactivated');

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., (*12)

protected $activatedAtColumn = 'my_column_name';

// or

public getActivatedAtColumn()
{
    return 'my_column_name';
}

The Versions

18/07 2017

dev-master

9999999-dev

Creating (de-) activatable Eloquent Models made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent activate activatable

18/07 2017

dev-develop

dev-develop

Creating (de-) activatable Eloquent Models made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent activate activatable

15/07 2017

v5.4

5.4.0.0

Creating (de-) activatable Eloquent Models made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent activate activatable

28/02 2015

v4.0

4.0.0.0

Creating (de-) activatable Eloquent Models made easy.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel eloquent activate activatable