承接 yaroslawww/nova-thinkit 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

yaroslawww/nova-thinkit

最新稳定版本:1.7.1

Composer 安装命令:

composer require yaroslawww/nova-thinkit

包简介

Laravel Nova small kit for quicker development.

README 文档

README

Packagist License Packagist Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality

Laravel Nova small kit for quicker development.

Installation

You can install the package via composer:

composer require think.studio/nova-thinkit

# optional publish configs
php artisan vendor:publish --provider="NovaThinKit\ServiceProvider" --tag="config"
# optional publish translations
php artisan vendor:publish --provider="NovaThinKit\ServiceProvider" --tag="lang"

Usage

Actions

Login to different guard

public function actions(NovaRequest $request)
{
    return [
        (new \NovaThinKit\Nova\Actions\LoginToDifferentGuard(
            route('dashboard.overview'),
            'owners_web',
            __('Login to owner dashboard'),
            __('Are you sure you want to continue?'),
        ))
            // optional callback how to find correct user
            ->findIdUsing(fn (Contact $model) => Owner::query()->where('contact_id', $model->getKey())->first()?->getKey())
            // other default method actions...
            ->canRun(fn ($request, Contact $model) => $model->role === "owner"),
    ];
}

Send reset password notification

use NovaThinKit\Nova\Actions\LoginToDifferentGuard;

public function actions(NovaRequest $request)
{
    return [
    ( \NovaThinKit\Nova\Actions\SendResetPasswordEmail::make('contacts', __('Send reset password'), __('Are you sure you want to continue?')))
            // optional callback how to find correct user
            ->findIdUsing(fn (Contact $model) => Owner::query()->where('contact_id', $model->getKey())->first()?->getKey())
            // other default method actions...
            ->canRun(fn ($request, Contact $model) => $model->role === "owner"),
    ];
}

Filters

Dynamic Boolean filter

\NovaThinKit\Nova\Filters\DynamicBooleanFilter::make([
    'Active' => 'active',
    'Paused' => 'paused',
]  /* options */, 'status' /* column to filter */, 'Status'  /* title */),

// Useful with HumanReadable enums:
\NovaThinKit\Nova\Filters\DynamicBooleanFilter::make(array_flip(CompanyStatus::options()), 'status', 'Status'),

Use filter for relation. For example add filter to Author to filter Posts:

\NovaThinKit\Nova\Filters\DynamicBooleanFilter::make(array_flip(CompanyStatus::options()), 'status', 'Posts Status')->forRelation('posts'),

Empty or null filed filter

\NovaThinKit\Nova\Filters\EmptyFieldFilter::make('post_title' /* column to filter */, 'Title'  /* title */),

Use filter for relation. For example add filter to Author to filter Posts:

\NovaThinKit\Nova\Filters\EmptyFieldFilter::make('posts.post_title', 'Posts Title'),

BelongsTo filter

Filter by related belongsTo relation.

use NovaThinKit\Nova\Filters\BelongsToFilter;

public function filters(NovaRequest $request)
{
    return [
        // type - this is belongsTo() relation method name
        new BelongsToFilter('type'),
        // or
        (new BelongsToFilter('type'))->setTitleKeyName('title'),
        // or
        (new BelongsToFilter('type'))->setFilterName('Filter by type'),
    ];
}

BelongsToMany filter

Filter by related belongsToMany relation.

public function filters(NovaRequest $request)
{
    return [
       \NovaThinKit\Nova\Filters\BelongsToManyFilter::make('tags')
                ->setTitleKeyName('name' /* label key name */)
                ->setFilterName('By tag'),
    ];
}

Metadata table

MetaFieldUpdater

If you have standalone table what contains meta values. You can use MetaFieldUpdater to quicker update these values from main resource:

public function fields(NovaRequest $request)
{
    $metaFieldUpdater = new \NovaThinKit\Nova\Helpers\MetaFieldUpdater(
        'metaData' /* hasMany relation method name */,
        'key' /* key name in neta table */,
        'value' /* data name in neta table */
    );

    return [
        $metaFieldUpdater->field(
            Select::make('University', 'university')->options(University::options())
        ),
        // ALso works with flexible
        $metaFieldUpdater->field(
            Flexible::make('Ethos list', 'cf-numeric_list_with_team')
                ->limit(20)
                ->useLayout(EthosItemLayout::class),
        ),
    ];
}

Feature image functionality

Add interface and trait to model

class Page extends Model implements \NovaThinKit\FeatureImage\Models\WithFeatureImage
{
    use \NovaThinKit\FeatureImage\Models\HasFeatureImage;
    
    // Optionally you can change default storage directory
    public function featureImageManagerDirectory(): string
    {
        return 'page/' . $this->getKey();
    }
    
    // Optionally you can change default image-manager
    protected function createFeatureImageManager(?string $tag = null): ImageManager
    {
    if (!$this->featureImageManager) {
            $this->featureImageManager = FeatureImageManager::fromConfig([
                'disk'                 => 'feature-images',
                'immutableExtensions' => [ '.svg', '.gif' ],
                'original'             => [
                    'methods' => [
                        'fit'      => [ \Spatie\Image\Manipulations::FIT_CROP, 2800, 1800 ],
                        'optimize' => [],
                    ],
                    'srcset'  => '2800w',
                ],
                'deletedFormats'       => [],
                'formats'              => [
                    'thumb' => [
                        'methods' => [
                            'fit'      => [ \Spatie\Image\Manipulations::FIT_CONTAIN, 450, 300 ],
                            'optimize' => [],
                        ],
                        'srcset'  => '450w',
                    ],
                ],
            ]);
        }
        
        if($tag === 'fooBar') {
            $this->featureImageManager->disk = 'baz';
        }

        return $this->featureImageManager;
    }
}

Add trait to resource

class Page extends Resource
{
    use \NovaThinKit\FeatureImage\Nova\HasFeatureImage;
    
    // ... other methods
    
    public function fields(NovaRequest $request)
    {
        return [
            // other fields
            $this->fieldFeatureImage(),
        ];
    }
}

Page templates (Dynamic fields based on template field)

Create template fields wrapper

namespace App\Nova\ResourceTemplates\Pages;

use NovaThinKit\Nova\Helpers\MetaFieldUpdater;
use NovaThinKit\Nova\ResourceTemplates\ResourceTemplate;

class HomePageTemplate extends ResourceTemplate
{
    public function fields(NovaRequest $request): array
    {
        $metaUpdater = new MetaFieldUpdater('meta', 'key', 'value');

        return [
            Text::make('Some Custom text', 'some_custom_text')
                ->hideWhenCreating()
                ->hideFromIndex()
                ->showOnPreview(),
            $metaUpdater->field(
                Text::make('Custom text', 'custom_text')
                    ->hideWhenCreating()
                    ->hideFromIndex()
                    ->showOnPreview(),
            ),
        ];
    }
}

Add mapping

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        \NovaThinKit\Nova\ResourceTemplates\TemplateFinder::templatesMap(Page::class, [
            'home'           => HomePageTemplate::class,
            'contact'        => ContactPageTemplate::class,
        ]);
    }
}

Finally, update resource

class Page extends Resource
{
    use \NovaThinKit\Nova\ResourceTemplates\HasTemplate;

    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable(),

            ...$this->templateFields($request),
        ];
    }
}

Credits

  • Think Studio

yaroslawww/nova-thinkit 适用场景与选型建议

yaroslawww/nova-thinkit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nova」 「laravel」 「think」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 yaroslawww/nova-thinkit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 yaroslawww/nova-thinkit 我们能提供哪些服务?
定制开发 / 二次开发

基于 yaroslawww/nova-thinkit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 137
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-15