定制 leko-team/laravel-published 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

leko-team/laravel-published

最新稳定版本:1.0.0

Composer 安装命令:

composer require leko-team/laravel-published

包简介

Ready-made solution for publishing an entity

README 文档

README

Latest Version

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_at or assign static::PUBLISHED_AT constant 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 PublishedTrait to 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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-13