定制 daniel-de-wit/nova-single-record-resource 二次开发

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

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

daniel-de-wit/nova-single-record-resource

最新稳定版本:v1.2.1

Composer 安装命令:

composer require daniel-de-wit/nova-single-record-resource

包简介

Laravel Nova Single Record Resource. Shows a link in the navigation bar directly to the only record of the resource

README 文档

README

License Latest Version on Packagist Total Downloads StyleCI

Adds the ability to create a navigation link directly to the detail page of a resource. Useful for models that will contain only a single record.

Prerequisites

Installation

$ composer require daniel-de-wit/nova-single-record-resource

Modify app/Nova/Resource.php to implement SingleRecordResourceInterface and the SupportSingleRecordNavigationLinks trait:

<?php

namespace App\Nova;

use DanielDeWit\NovaSingleRecordResource\Contracts\SingleRecordResourceInterface;
use DanielDeWit\NovaSingleRecordResource\Traits\SupportSingleRecordNavigationLinks;
use Laravel\Nova\Resource as NovaResource;

abstract class Resource extends NovaResource implements SingleRecordResourceInterface
{
    use SupportSingleRecordNavigationLinks;

    ...
}

Publish assets:

$ php artisan vendor:publish --provider="DanielDeWit\NovaSingleRecordResource\Providers\NovaSingleRecordResourceServiceProvider"

Update

When updating it is important to republish the assets, like so:

$ php artisan vendor:publish --force --provider="DanielDeWit\NovaSingleRecordResource\Providers\NovaSingleRecordResourceServiceProvider"

Uninstallation

Remove from composer

$ composer remove daniel-de-wit/nova-single-record-resource

Remove SupportSingleRecordNavigationLinks trait from your Nova Resources

use SupportSingleRecordNavigationLinks;

Remove the customized navigation template

rm resources/views/vendor/nova/resources/navigation.blade.php

Usage

Place the following method on models that have only a single record.

class MyResource extends Resource
{
    public static function singleRecord(): bool
    {
        return true;
    }
}

Optionally override the resource identifier.

class MyResource extends Resource
{
    /**
     * @return string|int
     */
    public static function singleRecordId()
    {
        return 1;
    }
}

How it works

Laravel Nova has the ability to override the Blade template used to render the navigation sidebar. The template is copied from Nova version v1.2.0 and altered with a few lines to support linking a resource directly to the detail view. When publishing vendor assets with the tag nova-views the template will be placed in the project resources/views/vendor/nova/resources folder.

View changes
@if ($resource::singleRecord())
    <router-link :to="{
    name: 'detail',
    params: {
        resourceName: '{{ $resource::uriKey() }}',
        resourceId: {{ $resource::singleRecordId() }}
    }
}" class="text-white text-justify no-underline dim">
        {{ $resource::label() }}
    </router-link>
@else
    <router-link :to="{
    name: 'index',
    params: {
        resourceName: '{{ $resource::uriKey() }}'
    }
}" class="text-white text-justify no-underline dim">
        {{ $resource::label() }}
    </router-link>
@endif

统计信息

  • 总下载量: 118.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 1
  • Forks: 9
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-06