seriousjelly/laravel-draftable
A Eloquent Draftable trait for Laravel
285
2
| Install | |
|---|---|
composer require seriousjelly/laravel-draftable |
|
| PHP: | >=5.4.0 |
| License: | MIT |
| Last Updated: | Mar 16, 2017 |
| Links: | GitHub · Packagist |
Maintainer: chrisbratherton
Laravel-Draftable
Easily add status to your models in Laravel 5.
Installation and Requirements
-
Install the
seriousjelly/laravel-draftablepackage via composer:$ composer require seriousjelly/laravel-draftable -
Add the service provider (
config/app.phpfor Laravel 5):# Add the service provider to the `providers` array 'providers' => array( ... 'Seriousjelly\Draftable\ServiceProvider', ) -
Ensure that your migrations contain a
statuscolumn by copy & pasting the below into your table migration file:# Add a status column to the table, feel free to change the default value. $table->boolean('status')->default(0);
Updating your Eloquent Models
Your models should use Draftable's trait:
use Seriousjelly\Draftable\DraftableTrait;
class MyModel extends Model
{
use Draftable;
}
Your model is now draftable!
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.
// Returns only live data
Posts::get();
//Returns live & draft data
Posts::withDrafts()->get();
Still To Do
- Add onlyDrafts() method.
- Add artisan command to create
statuscolumn on a table you choose (i.ephp artisan draftable:table table_name. - Allow the user to specify the column name in this package config (currently hardcoded to status).
Copyright and License
Laravel-Draftable was written by Chris Bratherton and released under the MIT License. See the LICENSE file for details.
Copyright 2015 Chris Bratherton