mathewparet / requires-publishing
向模型添加发布和取消发布的记录功能。
v1.0.0
2023-08-03 05:58 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^10.0
- illuminate/database: ^8.0|^9.0|^10.0
- illuminate/support: ^10.0
This package is not auto-updated.
Last update: 2024-09-27 09:35:37 UTC
README
提供模型发布的能力。
特性
- 发布/取消发布模型。
- 默认情况下,已发布的模型不会被任何查询考虑(添加全局作用域)。
安装
composer require mathewparet/requires-publishing
在迁移中定义一个字段来存储发布状态
// define a 'published_at' field of type dateTime and is nullable
$table->requiresPublishing();
或
// define a 'active_at' field of type dateTime and is nullable
$table->requiresPublishing('active_at');
将此功能添加到您的模型中
// ...
use mathewparet\RequiresPublishing\RequiresPublishing;
// ...
class User extends Authenticatable
{
// ...
use RequiresPublishing;
// ...
/**
* To use custom field name for publishing, use the below line. If the below line isn't
* defined, the field is assumed to be 'published_at'.
*/
const PUBLISHED_AT = 'active_at';
}
API参考
此包引入了以下方法
名称 | 可用性 | 描述 |
---|---|---|
requiresPublishing() | 蓝图 | 宏,用于定义一个字段,用于存储记录的发布状态。 |
publish() | 模型 | 标记模型为已发布。 |
publishQuietly() | 模型 | 标记模型为已发布而不触发任何事件。 |
unpublish() | 模型、构建器 | 标记模型为未发布。 |
unpublishQuietly() | 模型 | 标记模型为未发布而不触发任何事件。 |
withUnpublished() | 模型 | 将未发布的记录添加到作用域。 |
withoutUnpublished() | 模型 | 从作用域中移除未发布的记录。 |
onlyUnpublished() | 模型 | 将查询作用域限定为仅考虑未发布的记录。 |
事件
suspending
suspended
unsuspending
unsuspended