2017 © Pedro Peláez
 

library laravel-draftable

A Eloquent Draftable trait for Laravel

image

seriousjelly/laravel-draftable

A Eloquent Draftable trait for Laravel

  • Thursday, March 16, 2017
  • by chrisbratherton
  • Repository
  • 1 Watchers
  • 2 Stars
  • 271 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel-Draftable

Easily add status to your models in Laravel 5., (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

, (*3)

Installation and Requirements

  1. Install the seriousjelly/laravel-draftable package via composer:, (*4)

    $ composer require seriousjelly/laravel-draftable
    
  2. Add the service provider (config/app.php for Laravel 5):, (*5)

    # Add the service provider to the `providers` array
    'providers' => array(
        ...
        'Seriousjelly\Draftable\ServiceProvider',
    )
    
  3. Ensure that your migrations contain a status column by copy & pasting the below into your table migration file:, (*6)

    # Add a status column to the table, feel free to change the default value.
    $table->boolean('status')->default(0);
    

, (*7)

Updating your Eloquent Models

Your models should use Draftable's trait:, (*8)

use Seriousjelly\Draftable\DraftableTrait;

class MyModel extends Model
{
    use Draftable;
}

Your model is now draftable!, (*9)

, (*10)

Using this trait

By default all records that have a status of 0 will be excluded from your query results. To include draft records, all you need to do is call the withDrafts() method on your query., (*11)

// Returns only live data
Posts::get();

//Returns live & draft data
Posts::withDrafts()->get();

, (*12)

Still To Do

  • Add onlyDrafts() method.
  • Add artisan command to create status column on a table you choose (i.e php artisan draftable:table table_name.
  • Allow the user to specify the column name in this package config (currently hardcoded to status).

, (*13)

Laravel-Draftable was written by Chris Bratherton and released under the MIT License. See the LICENSE file for details., (*14)

Copyright 2015 Chris Bratherton, (*15)

The Versions

16/03 2017

dev-master

9999999-dev http://www.seriousjelly.com

A Eloquent Draftable trait for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Chris Bratherton

laravel eloquent status drafts live draftable