seriousjelly/laravel-draftable

Laravel的Eloquent Draftable特性

dev-master 2017-03-16 12:32 UTC

This package is auto-updated.

Last update: 2024-09-29 04:14:18 UTC


README

轻松为Laravel 5中的模型添加状态。

Latest Stable Version Total Downloads Latest Unstable Version License

安装和需求

  1. 通过composer安装seriousjelly/laravel-draftable

    $ composer require seriousjelly/laravel-draftable
  2. 添加服务提供者(Laravel 5的config/app.php

    # Add the service provider to the `providers` array
    'providers' => array(
        ...
        'Seriousjelly\Draftable\ServiceProvider',
    )
  3. 确保您的迁移包含一个status列,通过将以下内容复制到您的表迁移文件中

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

更新您的Eloquent模型

您的模型应使用Draftable的特性

use Seriousjelly\Draftable\DraftableTrait;

class MyModel extends Model
{
    use Draftable;
}

您的模型现在是可草稿的!

使用此特性

默认情况下,所有状态为0的记录都将被排除在查询结果之外。要包含草稿记录,只需在查询上调用withDrafts()方法即可。

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

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

待办事项

  • 添加onlyDrafts()方法。
  • 添加artisan命令以在您选择的表上创建status列(例如php artisan draftable:table table_name)。
  • 允许用户在此包的配置中指定列名(当前硬编码为status)。

版权和许可

Laravel-Draftable由Chris Bratherton编写,并使用MIT许可证发布。有关详细信息,请参阅LICENSE文件。

版权所有 2015 Chris Bratherton