2017 © Pedro Peláez
 

library laravel-model-active

Simple trait for scoping Eloquent models by 'active' boolean

image

daniel-de-wit/laravel-model-active

Simple trait for scoping Eloquent models by 'active' boolean

  • Monday, October 23, 2017
  • by daniel-de-wit
  • Repository
  • 1 Watchers
  • 0 Stars
  • 392 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 123 % Grown

The README.md

laravel-model-active

A trait for Laravel to only pull models marked as "active". When the trait is applied to a model, the queries will, by default, only find rows for that model where the active column has a value of 1., (*1)

Requirements

  • Laravel ^5.2

Installation

Add package to composer.json, (*2)

composer require daniel-de-wit/laravel-model-active, (*3)

Usage

Add active boolean to Eloquent Model:, (*4)

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddActiveModelSupportToArticleTable extends Migration
{
    public function up()
    {
        Schema::create('article', function (Blueprint $table) {
            $table->boolean('active')->default(true)->index();
        });
    }

    public function down()
    {
        Schema::table('article', function (Blueprint $table) {
            $table->dropColumn('active');
        });
    }
}

Add the Active trait to the model:, (*5)

<?php

class MyModel extends Eloquent
{
    use Active;

    ...

}

Removing Active Scope, (*6)

If you would like to remove the active scope for a given query, you may use the withoutGlobalScope method:, (*7)

<?php

    MyModel::withoutGlobalScope(ActiveScope::class)->get();

The Versions

23/10 2017

dev-master

9999999-dev https://github.com/daniel-de-wit/laravel-model-active

Simple trait for scoping Eloquent models by 'active' boolean

  Sources   Download

MIT

by Daniel de Wit

laravel eloquent

23/10 2017

0.0.1

0.0.1.0 https://github.com/daniel-de-wit/laravel-model-active

Simple trait for scoping Eloquent models by 'active' boolean

  Sources   Download

MIT

by Daniel de Wit

laravel eloquent