wamesk / stauses

1.2.0 2023-11-14 10:30 UTC

This package is auto-updated.

Last update: 2024-09-14 12:13:57 UTC


README

preview

preview

preview


2. 必需项

"wamesk/laravel-commands": "^1.0",
"wamesk/utils": "^1.1",
"wamesk/laravel-nova-language": "*",
"kongulov/nova-tab-translatable": "^2.0",
"norman-huth/nova-font-awesome-field": "^1.0"

3. 安装

  • 注册提供者

Wame\Statuses\StatusesServiceProvider::class,
  • vendor publish -- statusesServiceProvider

php artisan vendor:publish --provider="Wame\Statuses\StatusesServiceProvider"
php artisan vendor:publish --provider="Wame\LaravelNovaLanguage\PackageServiceProvider"
  • 添加并运行迁移

php artisan make:migration add_status_to_orders

/* add column to your model*/
$table->foreignUlid('status_id')->nullable()->constrained('statuses')->cascadeOnUpdate()->nullOnDelete();
php artisan migration
  • 运行种子

 php artisan db:seed --class=LanguageSeeder
 // php artisan db:seed --class=StatusSeeder

4. 使用

  • 添加到您的模型

    public function statuses(): BelongsTo
    {
        return $this->belongsTo(Status::class, 'status_id');  // Choose your model
    }
  • 向您的 Nova 模型添加字段

use App\Utils\Helpers\StatusFields;

...StatusFields::get($this, '0'), // set your model category if you use more categories
  • 添加到您的 Nova 菜单

MenuItem::resource(Statuses::class),
MenuItem::resource(Languages::class),

Nova::mainMenu(function (Request $request, Menu $menu) {
    return $menu->append(
        MenuSection::make(__('status.menu.settings'), [
            MenuItem::resource('\App\Nova\Status'),
            MenuItem::resource('\App\Nova\Language')
        ])->collapsable()->collapsible()->icon('cog')
    );
});

5. 配置

  • 编辑翻译

编辑翻译 resources/lang/sk/status.php

    'selected' => [
        '0' => 'prispevky',
        '1' => 'napady',
    ],

5. 更多选项/扩展

  • 如果您想为更多模型使用类别

在 Nova 模型 Status 中取消注释此行,并为模型添加翻译

 Select::make(__('status.field.category'), 'model')
  • 如果您想使用图标

取消注释此行

 \NormanHuth\FontAwesomeField\FontAwesome::make(__('Icon'), 'icon'),

并将 CSS 添加到 NovaSericeProvider

Nova::style('status_icons', resource_path('css/icon_fields.css'));

添加语言

在语言菜单中添加或删除语言,在 wame-statuses.phptab-translatable.php 中设置语言,

    'required' => 'required_lang:sk',
    'locales' => [
            'sk'
        ],

查看配置 https://github.com/wamesk/laravel-nova-status/blob/main/config/tab-translatable.php