pawelmysior/laravel-publishable
Composer 安装命令:
composer require pawelmysior/laravel-publishable
包简介
Toggle the published state of your Eloquent models easily
README 文档
README
Toggle the published state of your Eloquent models easily.
Installation
You can install the package via composer:
composer require pawelmysior/laravel-publishable
Versions
For details about which version of this package to use with your Laravel version please see the table below:
| Laravel Version | Package Version |
|---|---|
| <9.x | 1.x |
| 9.x | 2.x |
| 10.x | 3.x |
| 11.x | 4.x |
| 12.x | 5.x |
Preparation
To start you need to add a published_at nullable timestamp column to your table.
Put this in your table migration:
$table->timestamp('published_at')->nullable();
Now use the trait on the model
<?php namespace App; use Illuminate\Database\Eloquent\Model; use PawelMysior\Publishable\Publishable; class Post extends Model { use Publishable; }
Add Fillable Attribute
In Version 1.x, the published() function handles the update in a way where Laravel expects that the published_at field is fillable. As of Version 2.x, we not use fill functionality so the fillable attribute is no longer required.
Usage
You can now use those features:
// Get only published posts Post::published()->get(); // Get only unpublished posts Post::unpublished()->get(); // Check if the post is published $post->isPublished(); // Check if the post is unpublished $post->isUnpublished(); // Publish the post $post->publish(); // Unpublish the post $post->unpublish(); // Publish the post without firing model events $post->publishQuietly(); // Unpublish the post without firing model events $post->unpublishQuietly();
A post is considered published when the published_at is not null and in the past.
A post is considered unpublished when the published_at is null or in the future.
Security
If you discover any security-related issues, please email security@jaymeh.co.uk instead of using the issue tracker.
Contributing
Any contributions to this repository are welcomed. Please be aware that we are using conventional commits to assist in self documentation and reduce manual work involved with releases.
License
The MIT License (MIT). Please see License File for more information.
pawelmysior/laravel-publishable 适用场景与选型建议
pawelmysior/laravel-publishable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.23k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2017 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「trait」 「laravel」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pawelmysior/laravel-publishable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pawelmysior/laravel-publishable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pawelmysior/laravel-publishable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Eloquent model trait for translatable resource
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Help to manage meta data on Laravel Eloquent model
A package to cast json fields, each sub-keys is castable
Trait providing methods to set class properties with an array.
Expansion traits for Yii2 components
统计信息
- 总下载量: 19.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 21
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-06