bbs-lab/nova-cloudinary-field 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bbs-lab/nova-cloudinary-field

Composer 安装命令:

composer require bbs-lab/nova-cloudinary-field

包简介

A Cloudinary Media Library field for Laravel Nova.

README 文档

README

Latest Version on Packagist Software License Total Downloads

A Cloudinary Media Library field and tool for Laravel Nova.

cloudinary editor field screenshot

Contents

Installation

You can install the package via composer:

composer require bbs-lab/nova-cloudinary-field

The package will automatically register itself.

You can publish the config-file with:

php artisan vendor:publish --provider="BBSLab\CloudinaryField\CloudinaryFieldServiceProvider" --tag="config"

This is the contents of the published config file:

<?php

declare(strict_types=1);

return [

    'default' => [
        'cloud' => env('NOVA_CLOUDINARY_DEFAULT_CLOUD'),
        'username' => env('NOVA_CLOUDINARY_DEFAULT_USERNAME'),
        'key' => env('NOVA_CLOUDINARY_DEFAULT_KEY'),
        'secret' => env('NOVA_CLOUDINARY_DEFAULT_SECRET'),
    ],

];

Usage

You can use the BBSLab\CloudinaryField\Cloudinary field in your Nova resource:

<?php

namespace App\Nova;

declare(strict_types=1);

namespace App\Nova;

class BlogPost extends Resource
{
    // ...
    
    public function fields(Request $request)
    {
        return [
            // ...

            Cloudinary::make('Image'),

            // ...
        ];
    }
    
}

Important

By default the field stores an array of data, you must cast your attribute as an array.

Advanced usage

Multiple selection

When using the Cloudinary field on your Nova resource, you can tell the tool to allow multiple selection for your attribute.

By default, the tool will only allow single selection.

<?php

declare(strict_types=1);

namespace App\Nova;

use BBSLab\CloudinaryField\Cloudinary;

class BlogPost extends Resource
{
    // ...
    
    public function fields(Request $request)
    {
        return [
            // ...

            Cloudinary::make('Image')
                ->multiple(),

            // ...
        ];
    }
    
}

Limit the number of selected files

You can limit the number of selected files by using the limit method.

<?php

declare(strict_types=1);

namespace App\Nova;

use BBSLab\CloudinaryField\Cloudinary;

class BlogPost extends Resource
{
    // ...
    
    public function fields(Request $request)
    {
        return [
            // ...

            Cloudinary::make('Image')
                ->multiple()
                ->limit(10),

            // ...
        ];
    }
    
}

On-demand configuration

You can use the following methods to set some configuration on the field:

  • cloud(string $cloud): Set the cloud name.
  • username(string $username): Set the username.
  • key(string $key): Set the API key.
  • secret(string $secret): Set the API secret.

Also, you can use the configureUsing method to set the configuration on the field:

<?php

declare(strict_types=1);

namespace App\Nova;

use BBSLab\CloudinaryField\Cloudinary;use Laravel\Nova\Http\Requests\NovaRequest;

class BlogPost extends Resource
{
    // ...
    
    public function fields(Request $request)
    {
        return [
            // ...

            Cloudinary::make('Image')
                ->configureUsing(function (NovaRequest $request) {
                    return [
                        'cloud' => 'my_cloud',
                        'username' => 'my_username',
                        'key' => 'my_key',
                        'secret' => 'my_secret',
                    ];
                });

            // ...
        ];
    }
    
}

Dependent Fields

You may use the dependsOn method to conditionally display the field based on the value of another field. See the example below:

<?php

declare(strict_types=1);

namespace App\Nova;

use BBSLab\CloudinaryField\Cloudinary;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class BlogPost extends Resource
{
    // ...

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

            Text::make('Title')
                ->sortable()
                ->rules('required', 'max:255'),

            Boolean::make('Has Image')
                ->sortable()
                ->rules('required'),

            Cloudinary::make('Image')
                ->rules('nullable')
                ->fullWidth()
                ->hide()
                ->dependsOn('has_image', function (Cloudinary $field, NovaRequest $request, FormData $formData) {
                    if ($formData->has_content) {
                        $field
                            ->show()
                            ->rules('required');
                    } else {
                        $field->hide();
                    }
                }),
        ];
    }
}

Tip

More information about dependent fields can be found in the official documentation.

Tool

The package also provides a tool to directly access the Cloudinary Media Library.

You may register the tool in your NovaServiceProvider:

<?php

declare(strict_types=1);

namespace App\Providers;

use BBSLab\CloudinaryField\NovaCloudinary;
use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    // ...

    public function tools(): array
    {
        return [
            NovaCloudinary::make(),
        ];
    }
}

Screenshots

Index

Index view

Detail

Detail view

Form

Create view Modal view Edit view

Tool

Tool

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email paris@big-boss-studio.com instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

bbs-lab/nova-cloudinary-field 适用场景与选型建议

bbs-lab/nova-cloudinary-field 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.05k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 bbs-lab/nova-cloudinary-field 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-14