pppcreative/select-badge
Composer 安装命令:
composer require pppcreative/select-badge
包简介
Package combines Select field and Badge field, adds styled classes in CSS and adds functions such as icons(), map(), addTypes(), options(), labels(). Added to BelongsBaadge !
README 文档
README
1. Preview
2. Info
Package combines Select field and Badge field, adds styled classes in CSS and adds functions such as icons(), map(), addTypes(), options(), labels().
- You can use to like simple css Badge
How use Badge
->displayUsing(fn($value)=> '<span class="' .config('wame-badge.info-white'). '">' . $value . '</span>')->asHtml() ->displayUsing(fn($value)=> '<span class="' .config('wame-badge.info'). '">' . $value . '</span>')->asHtml()
->displayUsing(fn($value)=> '<span class="status-bg-teal s-badge">' . $value . '</span>')->asHtml(), ->displayUsing(fn($value)=> '<span class="status-bg-primary s-badge">' . $value . '</span>')->asHtml(),
Added files:
resources/css/labels-status.css - register file to NovaProvider Nova::style('label-statuses', resource_path('css/label-statuses.css'));, config/wame-badge.php - config('wame-badge.warning'), Models/Trait/BadgeStatuses.php --add to model, App\Utils\Helpers\SelectBadge.php function SelectBadge;
Function
public static function select ($select, $options, $types, $icons){ return [ Select::make(__('fields.' .$select), $select) ->filterable() ->displayUsingLabels() ->onlyOnForms() ->options($options) ->rules('required')->required(), Badge::make(__('fields.' . $select), $select) ->sortable() ->map($options) ->hideWhenCreating()->hideWhenUpdating() ->addTypes($types) ->icons($icons ? $icons : $types) ->labels($options), ]; } public static function badge ($select, $options, $types, $icons){ return [ Badge::make(__('fields.' . $select), $select) ->map($options) ->hideWhenCreating()->hideWhenUpdating() ->addTypes($types) ->icons($icons ? $icons : $types) ->labels($options), ]; }
3. Instalation
php artisan vendor:publish --provider="Wame\SelectBadge\SelectBadgeServiceProvider"
you can use config classes or register Nova::style('label-statuses', resource_path('css/label-statuses.css')); in NovaServiceProvider.php
4. Usage
Models/Trait/BadgeStatuses.php use App\Models\Traits\BadgeStatuses; use BadgeStatuses;
use App\Utils\Helpers\SelectBadge; //...SelectBadge::select('place_execution', $this->place(), $this->placeMap(), $this->placeType(), $this->placeIcons() ), ...SelectBadge::select('place_execution', $this->place(), $this->place('type'), $this->place('icon') ),
const PLACE = [ 'OFFICE' => 1, 'HALL' => 2, 'EXTERIOR' => 3, 'MOBILE' => 4, ]; public function place($value=null){ $variable = [ __('fields.office'), __('fields.hall'), __('fields.exterior'), __('fields.mobile'), ]; $icon = [ 'collection', 'office-building', 'cloud', 'switch-vertical', ]; $type = [ 'status-color-blue', 'status-color-teal', 'status-color-coral', 'status-color-teal2', ]; $data = ($value === 'value') ? $variable : (($value === 'icon') ? $icon : (($value === 'type') ? $type : null)); if ($value == null) return array_combine(array_values(self::PLACE), $variable); if (is_array($data)) return array_combine($variable, $data); else return array_fill_keys($variable, $data); }
5. Configuration / Customization
### You can add your custom classes
If you dont want Icons use null:
$icon = ''; ...SelectBadge::select('place_execution', $this->place(), $this->place('type'), place('icon') ),
Icons can find here: https://v1.heroicons.com/
6. Badges class:
| red | green | green2 | blue | ice | teal | teal2 | coral | aquamarine | golden | orange | orange-light | green-light | green-dark | pink | purple |
| config('wame-badge.error) | denied | approved | info | default | warning |
| config('wame-badge.error-white') | denied-white | approved-white | info-white | default-white | warning-white |
config classes:
- config('wame-badge.error')
- ...
css classes:
- status-bg-[color]
- status-color-[color]
- status-line-[color]
- status-border-[color]
- ...
more:
- primary
- secondary
- none
OR OLDER CODE
Kliknite sem pre zobrazenie obsahu
const OFFICE = 1, HALL = 2, EXTERIOR = 3, MOBILE = 4; public function place(): array { return [ self::OFFICE => __('fields.office'), self::HALL => __('fields.hall'), self::EXTERIOR => __('fields.exterior'), self::MOBILE => __('fields.mobile'), ]; } // uprava css / nalepky // you can use css class or tailwind classes from config too : config('wame-badge.info') public function placeType(){ return [ 'office' => 'status-color-blue', 'hall' => 'status-color-teal', 'exterior' => 'status-color-coral', 'mobile' => 'status-color-aquamarine', // 'edit' => config('wame-badge.warning'), ]; } // Add Icons public function placeIcons(){ return [ 'office' => 'exclamation-circle', 'hall' => 'check-circle', 'exterior' => 'x-circle', 'mobile' => 'document-text', ]; }
OR OLDER CODE
Kliknite sem pre zobrazenie obsahu
const PLACE = [ OFFICE = 1, HALL = 2, EXTERIOR = 3, MOBILE = 4 ]; public function placeVariable ($value = 'value') { $variable = [ __('fields.office'), __('fields.hall'), __('fields.exterior'), __('fields.mobile'), __('fields.other'), ]; $type = [ 'status-color-blue', 'status-color-teal', 'status-color-coral', 'status-color-teal2', 'status-color-default', ]; $icon = 'collection'; if ($value === 'value') return $variable; if ($value === 'icon') return $icon; if ($value === 'type') return $type; } public function place($type=null){ if ($type == null) return array_combine(array_values(self::PLACE), $this->placeVariable()); if (is_array($this->placeVariable($type))){ return array_combine($this->placeVariable(), $this->placeVariable($type)); } else return array_fill_keys($this->placeVariable(), $this->placeVariable($type)); }
pppcreative/select-badge 适用场景与选型建议
pppcreative/select-badge 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「select」 「badge」 「status」 「selectBadge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pppcreative/select-badge 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pppcreative/select-badge 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pppcreative/select-badge 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
Country select field type.
Add gamification in laravel app with reputation point and badges support
Photo Rest Bundle for symfony2
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-09


