crayon/nova-additional-fields 问题修复 & 功能扩展

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

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

crayon/nova-additional-fields

最新稳定版本:1.0.0

Composer 安装命令:

composer require crayon/nova-additional-fields

包简介

A Laravel Nova package that allows you to dynamically append inputs to your resources.

README 文档

README

A laravel nova package that allows you to dynamically append inputs to your resources based on a database table.

Installation

composer require crayon/nova-additional-fields

Documentation

Assuming you are building an eCommerce website, and you have different types of products. It would be uncomfortable if you want the admin of the website to enter custom values for each product.

So this package allows you to define form inputs in a Nova resource;

Migration

Product fields (Each field belongs to a category):

Schema::create('product_fields', function (Blueprint $table) {
    $table->id();
    $table->json('text');
    $table->string('type');
    $table->string('name');
    $table->text('options')->nullable();
    $table->unsignedBigInteger('category_id');
    $table->softDeletes();
    $table->timestamps();

    $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
});

Resource Usage

The additional fields will be loaded from an endpoint (Fields that belong to the category we selected)

AdditionalFields::make('Additional Fields', 'fields')
    ->parent('category')
    ->endpoint('/api/category/{category}/fields')
    ->hideFromIndex(),

Endpoint

Route

Route::get('/category/{category}/fields', [\App\Http\Controllers\Api\NovaHelpers\NovaCategoryController::class, 'fields']);

Controller

/**
 * Get available fields by Category ID
 *
 * @param $category
 * @return mixed
 */
public function fields($category)
{
    return Category::findOrFail($category)->fields->map(fn($field) => [
        'id' => $field->id,
        'text' => $field->text,
        'type' => $field->type,
        'name' => $field->name,
        'options' => $field->options
    ]);
}

The fields will be loaded into your resource based on the ones you added to your database. ProductFields resource find it here

Screenshots

nova-additional-fields nova-additional-fields

Conclusion

Laravel Nova is a great piece of software that will boost your productivity when it comes to building admin panels. With a little of customization through custom packages & fields. You are ready to rock 'N roll.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固