Laravel-Draftable
Easily add status to your models in Laravel 5., (*1)
, (*2)
, (*3)
Installation and Requirements
-
Install the seriousjelly/laravel-draftable package via composer:, (*4)
$ composer require seriousjelly/laravel-draftable
-
Add the service provider (config/app.php for Laravel 5):, (*5)
# Add the service provider to the `providers` array
'providers' => array(
...
'Seriousjelly\Draftable\ServiceProvider',
)
-
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)
Copyright and License
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)