承接 creode/laravel-nova-assets 相关项目开发

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

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

creode/laravel-nova-assets

Composer 安装命令:

composer require creode/laravel-nova-assets

包简介

Takes the existing Laravel Assets module and adds functionality to make it work in Nova.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Takes the existing Laravel Assets module and adds hookable functionality to make it work in Nova.

Installation

You can install the package via composer:

composer require creode/laravel-nova-assets

You can publish the config file with:

php artisan vendor:publish --tag="nova-assets-config"

This is the contents of the published config file:

// config for Creode/LaravelNovaAssets
return [
    /*
    |--------------------------------------------------------------------------
    | Default Upload Accepted Mime Types
    |--------------------------------------------------------------------------
    |
    | This value contains the default bulk fields which will be rendered when
    | doing a bulk upload. You can add or remove fields as you wish.
    |
    */

    'default_upload_accepted_mime_types' => [
        'image/*',
        'application/zip',
        'zip',
        'application/pdf',
    ],

    /*
    |--------------------------------------------------------------------------
    | Allowed Zip File Extensions
    |--------------------------------------------------------------------------
    |
    | This value contains an array of allowed file extensions which will be
    | pulled when extracting zip files during a bulk upload action.
    |
    */

    'accepted_zip_file_extensions' => [
        'png',
        'jpeg',
        'jpg',
        'webp',
        'pdf',
    ],

    /*
    |--------------------------------------------------------------------------
    | Asset Policy
    |--------------------------------------------------------------------------
    |
    | This value contains the policy which will be used when verifying if a
    | user can perform an action on an asset. You can change this to your own
    | policy if you wish.
    |
    */

    'asset_policy' => \Creode\LaravelNovaAssets\Policies\AssetPolicy::class,

    /*
    |--------------------------------------------------------------------------
    | Image Driver
    |--------------------------------------------------------------------------
    |
    | This value contains the image driver which will be used when generating
    | thumbnails. You can change this to your own driver if you wish. Drivers
    | must implement the Intervention\Image\Interfaces\DriverInterface
    | interface.
    |
    | This can be one of the following:
    | Intervention\Image\Drivers\Gd\Driver::class
    | Intervention\Image\Drivers\Imagick\Driver::class
    |
    */
    'image_driver' => Intervention\Image\Drivers\Gd\Driver::class,

    /*
    |--------------------------------------------------------------------------
    | Traffic Cop
    |--------------------------------------------------------------------------
    |
    | Indicates whether Nova should check for modifications between viewing
    | and updating a resource.
    |
    */
    'traffic_cop' => true,

    /*
    |--------------------------------------------------------------------------
    | Show Max Upload Size
    |--------------------------------------------------------------------------
    |
    | Indicates whether to show the max upload size in the asset resource.
    |
    */
    'show_max_upload_size' => false,
];

Usage

The purpose of this module is to use the existing assets model class and wrap it into a Nova resource. This allows us to use the existing functionality of the assets module in Nova. We use some hookable functionality which is documented below that gives any child modules the ability to add custom fields and actions to the resource.

Registering Custom Resource Fields

You can register custom resource fields to appear in both the standard Nova pages (detail, edit, create) and the Bulk Asset Upload action. To do this you need to listen for the DefineAssetFieldsEvent event and add your fields to the $fields array. For a full list of Nova fields please look at the Nova documentation.

Event::listen(function (DefineAssetFieldsEvent $event) {
    $event->fields[] = Text::make('Folder', 'folder_id');
});

Registering Custom Resource Actions

You can register custom resource actions to appear on the Asset resource. To do this you need to listen for the DefineAssetActionsEvent event and add your actions to the $actions array. These just use Nova's standard Actions functionality. For details about defining actions please look at the Nova documentation.

Event::listen(function (DefineAssetActionsEvent $event) {
    $event->actions[] = TestActionClass::make();
});

Registering Custom Bulk Asset Fields

You can register custom bulk asset fields to appear on the Bulk Asset Upload action. To do this you need to listen for the DefineBulkAssetFieldsEvent event and add your fields to the $fields array. For a full list of Nova fields please look at the Nova documentation.

Event::listen(function (DefineBulkAssetFieldsEvent $event) {
    $event->fields[] = Text::make('Folder', 'folder_id');
});

Insert a field after another one

As of version 1.4.0 of this module, you can now run a helper function to add an attribute in after another one. This can be done by running the following:

Event::listen(function (DefineAssetFieldsEvent $event) {
    $event->addFieldAfter('name', Text::make('Folder', 'folder_id'));
});

This will then inject the field directly after the other. This is useful if you want to add a field after a specific field but don't want to have to worry about the order of the fields in the array. The only caveat here is that if the field with the provided first attribute doesn't exist, it will not add the field.

Permissions

This module exposes a new permission seeder class which will need to be published to your application in order to grant permissions to the new resource. To do this you need to run the following command:

php artisan vendor:publish --tag="nova-assets-seeders"

This will create a new AssetRoleAndPermissionSeeder.php file within your database/seeders directory. This will need to be run in order to grant permissions to the new resource. You can run this by running the following command:

php artisan db:seed --class=AssetRoleAndPermissionSeeder

You should now see in your database a collection of permissions and a new role called asset-manager. This role will have all the permissions required to manage assets. Before running this, it requires the setup of any tables for the spatie/laravel-permissions package. Please see the documentation for more information.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

creode/laravel-nova-assets 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-20