leko-team/laravel-published
最新稳定版本:1.0.0
Composer 安装命令:
composer require leko-team/laravel-published
包简介
Ready-made solution for publishing an entity
README 文档
README
This package can associate published date with Eloquent models. It provides a simple API to work with.
Installation
The library can be installed via Composer:
composer require leko-team/laravel-published
Configuration
To be able publishing eloquent entities you need:
- Add migration with column
published_ator assignstatic::PUBLISHED_ATconstant with the name of the column you want to use.
php artisan make:migration add_published_at_column_in_`your-table`_table
Schema::table('your-table', function (Blueprint $table) { $table->timestamp('published_at')->nullable()->index(); });
If you have existing records in your table you maybe want to update them with current date. Or perhaps you want to add current date as default value.
- Add trait
PublishedTraitto your model.
use PublishedTrait;
Examples
Base
To publish entity:
$review = Review::first(); $review->publish();
Publish by specific datetime:
$review = Review::first(); $review->publish(pass here carbon entity);
To unpublish entity:
$review = Review::first(); $review->unpublish();
Scopes
By default from published entity return only published records. You can change this by applying scope to your Eloquent model.
- notPublished
$review = Review::notPublished()->get();
Returns all not published record with null in published_at include records that must be published in the future.
- withUnpublished
$review = Review::withUnpublished()->get();
Returns all records.
- withoutPublished
$review = Review::withoutPublished()->get();
Returns all unpublished record with null in published_at.
Credits
A big thank you to Laravel Package for helping out build package with step by step guide.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-13