lambdadigamma/laravel-publishable
Composer 安装命令:
composer require lambdadigamma/laravel-publishable
包简介
A Laravel Eloquent model trait for publishing and unpublishing
README 文档
README
A simple package for making Laravel Eloquent models 'publishable'. Not published models are excluded from queries by default but can be queried via extra scope.
This package allows easy publishing and unpublishing of models by combining scopes and macros.
The package supports Laravel 8 through 13.
How does it work?
The package provides a trait Publishable for your Eloquent model.
Your database schema has to have a published_at datetime column so that the trait can read and write it.
By reading this column the package can determine which models already have been published and provide the requested models.
Installation
You can install the package via composer:
composer require lambdadigamma/laravel-publishable
Usage
Migrations
The Publishable trait works similarly to Laravel's SoftDeletes trait. This package provides a macro for Laravel's Migration Builder.
Just use the publishedAt macro in your migration to get started:
Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('text'); $table->timestamps(); $table->publishedAt(); // Macro provided by the package });
Eloquent Model Trait
After providing a published_at timestamp on your model, you can use the Publishable trait on your Eloquent model:
namespace App\Models; use \Illuminate\Database\Eloquent\Model; use \LaravelPublishable\Publishable; class Post extends Model { use Publishable; ... }
Extensions
The extensions shipped with this trait include; publish, unpublish, withNotPublished, withoutPublished, onlyPublished and can be used accordingly:
$post = Post::first(); $post->publish(); $post->publishAt(now()->addHour(1)); $post->scheduleFor(new Carbon('2021-04-01 10:00:00')); $post->unpublish(); $postsWithNotPublished = Post::query()->withNotPublished(); $onlyNotPublishedPosts = Post::query()->onlyNotPublished();
When not specifing any additional scopes, all not published models are excluded from the query by default (withoutNotPublished) to prevent leaks of not published data.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email github@lambdadigamma.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
lambdadigamma/laravel-publishable 适用场景与选型建议
lambdadigamma/laravel-publishable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.07k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「publish」 「laravel」 「models」 「scope」 「unpublish」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lambdadigamma/laravel-publishable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lambdadigamma/laravel-publishable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lambdadigamma/laravel-publishable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Rabbitevents common package
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
A Laravel Eloquent model trait for publishable resource
Book publishing application
The Publisher component of the RabbitEvents package.
统计信息
- 总下载量: 1.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 13
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-28