novius/laravel-nova-publishable

A Laravel Nova package for publishable fields

2.0.2 2023-10-13 07:15 UTC

This package is auto-updated.

Last update: 2024-04-13 08:22:37 UTC


README

Packagist Release License: AGPL v3

Introduction

This package allows you to manage Laravel Models which user Laravel Publishable in Laravel Nova.

Requirements

  • Laravel Nova >= 4.0
  • Laravel Publishable >= 1.0
  • Laravel >= 8.0

Installation

You can install the package via composer:

composer require novius/laravel-nova-publishable

Add Publishable trait on your Nova Resource:

use Laravel\Nova\Resource;
use Novius\LaravelNovaPublishable\Nova\Traits\Publishable;

class Post extends Resource
{
    use Publishable;

Then you can insert Publishable fields on your Nova Resource. You can also add the Publication Status Filter.

class Post extends Resource
{
    public function fields(NovaRequest $request): array
    {
        return [
            PublicationBadge::make(), // Only display on not forms
            PublicationStatusField::make()->onlyOnForms(),
            PublishedFirstAt::make()->hideFromIndex(),
            PublishedAt::make()->onlyOnForms(),
            ExpiredAt::make()->onlyOnForms(),
        ];
    }

    public function filters(NovaRequest $request): array
    {
        return [
            new PublicationStatus(),
        ];
    }

You can use the UpdatePlucationStatus action to mass update the publication status of your models.

    public function actions(Request $request): array
    {
        return [
            UpdatePublicationStatus::make(),
        ];
    }

Lang files

If you want to customize the lang files, you can publish them with:

php artisan vendor:publish --provider="Novius\LaravelNovaPublishable\LaravelNovaPublishableServiceProvider" --tag="lang"

Lint

Lint your code with Laravel Pint using:

composer run-script lint

Licence

This package is under GNU Affero General Public License v3 or (at your option) any later version.