joshua060198/nova-simple-status-with-enum
Composer 安装命令:
composer require joshua060198/nova-simple-status-with-enum
包简介
Simple status field for Laravel Nova
README 文档
README
Simple status indicator using badge field.
Dependency
This package uses:
So, make sure to check out the installation instructions on those packages first.
Installation
composer require joshua060198/nova-simple-status-with-enum
Screenshot
Index / Detail
Edit
Usage
-
Create your enum class and apply
MappableStatustrait.<?php namespace App\Enums; use BenSampo\Enum\Enum; use Joshua060198\NovaSimpleStatusWithEnum\MappableStatus; final class CategoryStatus extends Enum { use MappableStatus; const Active = 1; const NotActive = 0; }
-
MappableStatustrait provide a static functiongetMappedStatus()to get status mapping for css classes inBadgefield. You can override this to your need. Important: you need to provide all mapping togetMappedStatus()function!<?php namespace App\Enums; use BenSampo\Enum\Enum; use Joshua060198\NovaSimpleStatusWithEnum\MappableStatus; final class CategoryStatus extends Enum { use MappableStatus; const Active = 1; const NotActive = 0; const MyCustomStatus = 2; public static function getMappedStatus() { $parent = static::$defaultMappedStatus; $new = [ 'My Custom Status' => 'bg-success-dark text-light' ]; return array_merge($parent, $new); } }
-
Apply it in resource
// app/Nova/Order.php use Joshua060198\EditableStatusCard\EditableStatusCard; class Category extends Resource { ... public function fields(Request $request) { return [ StatusView::make($this->status, CategoryStatus::class), StatusForm::make(CategoryStatus::class) ] } ... }
Constructor
StatusForm
You need to pass the enum class that holds all of constant for your status. The next param is the same as regular nova fields.
Example
StatusForm::make(CategoryStatus::class, 'Custom Status', 'my_status')
StatusView
There are two required params for this. The first one give the actual value for your status field, and the second one pass the enum class that holds all of constant.
Example
StatusView::make($this->my_custom_status, CategoryStatus::class, 'My Status')
IMPORTANT!!
-
This status field will split your constant variable by capital letter and displayed them with spaces. For example:
final class CategoryStatus extends Enum { const NotActive = 0; }
will be displayed as
-
You need to provide the mapping for your enum constant in
getMappedStatus()function. For example, this would produce an error later:final class CategoryStatus extends Enum { use MappableStatus; const FirstCustomStatus = 0; const AnotherStatus = 1; const Active = 2; }
You have to provide the mapping for
FirstCustomStatusandAnotherStatuslike this code:final class CategoryStatus extends Enum { use MappableStatus; const FirstCustomStatus = 0; const AnotherStatus = 1; const Active = 2; public static function getMappedStatus() { $parent = static::$defaultMappedStatus; $new = [ 'First Custom Status' => 'custom-class', 'AnotherStatus' => 'bg-dark text-light' ]; return array_merge($parent, $new); } }
-
Default mapped status value are :
public static $defaultMappedStatus = [ 'Active' => 'bg-success-light text-success-dark', 'Warning' => 'bg-warning-light text-warning-dark', 'Not Active' => 'bg-danger-light text-danger-dark', 'Approved' => 'bg-success-light text-success-dark', 'Waiting Approval' => 'bg-warning-light text-warning-dark', 'Not Approved' => 'bg-danger-light text-danger-dark', 'Delivered' => 'bg-success-light text-success-dark', 'Delivering' => 'bg-warning-light text-warning-dark', 'Not Delivered' => 'bg-danger-light text-danger-dark', 'Paid' => 'bg-success-light text-success-dark', 'Not Paid' => 'bg-danger-light text-danger-dark', ];
License
The MIT license.
joshua060198/nova-simple-status-with-enum 适用场景与选型建议
joshua060198/nova-simple-status-with-enum 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「enum」 「badge」 「status」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joshua060198/nova-simple-status-with-enum 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joshua060198/nova-simple-status-with-enum 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joshua060198/nova-simple-status-with-enum 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Serves functionality of healthchecks of your application
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
Enum type behavior for Yii2 based on class constants
404 'not found' and 403 'forbidden' error handlers. The 404 handler shows custom content for missing pages but not resources like CSS or JS. The 403 handler redirects to a login URL on unauthorized access.
A PHP Abstract Enum Class
Provide status and health api endpoints
统计信息
- 总下载量: 64
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-14


