novius/laravel-publishable
最新稳定版本:3.1.1
Composer 安装命令:
composer require novius/laravel-publishable
包简介
A Laravel Eloquent model trait for publishable resource
README 文档
README
Introduction
A package for making Laravel Eloquent models "publishable" using 4 states : draft, published, unpublished and scheduled.
Manage an additional published_first_at date for order by and display.
Requirements
- Laravel >= 10.0
- PHP >= 8.2
NOTE: These instructions are for Laravel >= 10.0 and PHP >= 8.2 If you are using prior version, please see the previous version's docs.
Installation
You can install the package via composer:
composer require novius/laravel-publishable
php artisan vendor:publish --provider="Novius\Publishable\LaravelPublishableServiceProvider" --tag=lang
Usage
Migrations
Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('text'); $table->timestamps(); $table->publishable(); // Macro provided by the package });
Eloquent Model Trait
namespace App\Models; use \Illuminate\Database\Eloquent\Model; use \Novius\LaravelPublishable\Publishable; class Post extends Model { use Publishable; ... }
Extensions
The extensions shipped with this trait include; notPublished, published, onlyDrafted, onlyExpired, onlyWillBePublished and can be used accordingly:
$post = Post::first(); $post->isPublished(); $postsPublished = Post::all(); $postsPublished = Post::query()->published(); $onlyNotPublishedPosts = Post::query()->notPublished(); $onlyDraftedPosts = Post::query()->onlyDrafted(); $onlyExpiredPosts = Post::query()->onlyExpired(); $onlyWillBePublishedPosts = Post::query()->onlyWillBePublished();
Testing
composer run test
CS Fixer
Lint your code with Laravel Pint using:
composer run cs-fix
Licence
This package is under GNU Affero General Public License v3 or (at your option) any later version.
统计信息
- 总下载量: 8.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2023-06-23