optimistdigital / nova-table-field

Laravel Nova 的表格字段

2.1.0 2023-09-29 13:54 UTC

This package is auto-updated.

Last update: 2024-08-29 16:03:38 UTC


README

Latest Version on Packagist Total Downloads

简单的 Laravel Nova 表格字段。

表单视图

Form View GIF

安装

通过 Composer 在 Laravel Nova 项目中安装此包

composer require outl1ne/nova-table-field

使用方法

Table 字段提供了一个便捷的界面来编辑存储在 JSON 等效列中的行和列。

use Outl1ne\NovaTableField\Table;

public function fields(Request $request)
{
    return [
        Table::make('Countries')

        // Optional:
        ->disableAdding() // Disable adding new rows and columns
        ->disableDeleting() // Disable deleting rows and columns
        ->minRows(1) // The minimum number of rows in the table
        ->maxRows(10) // The maximum number of rows in the table
        ->minColumns(1) // The minimum number of columns in the table
        ->maxColumns(10) // The maximum number of columns in the table
        ->defaultValues([ // Default values for new rows
            ['column_1', 'column_2'], // This is a row
            ['column_3', 'column_4'], // This is a row
        ])
    ];
}

注意,您还必须在模型中将 JSON 数据转换为 array

protected $casts = ['countries' => 'array'];

本地化

可以使用以下发布命令发布翻译文件

php artisan vendor:publish --provider="Outl1ne\NovaTableField\FieldServiceProvider" --tag="translations"

然后您可以根据需要编辑字符串。