Add "fatagroup/eloquent-status": "dev-master"
in your composer.json
, and run:
$ composer update
Make sure you have status
column like this in database table.
$table->enum('status', array('DRAFT', 'APPROVED'))->default('DRAFT');
In your model:
<?php
class Post extends Eloquent {
use \Fatagroup\EloquentStatus\StatusTrait;
const DRAFT = 'DRAFT';
const APPROVED = 'APPROVED';
// ...
}
<?php
$posts = Post::all();
// SELECT * FROM `posts` WHERE `status` = `APPROVED`
$posts = Post::withDraft()->get();
// SELECT * FROM `posts`
$posts = Post::onlyDraft()->get();
// SELECT * FROM `posts` WHERE `status` = `DRAFT`
MIT License