PHP code example of pppcreative / select-badge

1. Go to this page and download the library: Download pppcreative/select-badge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pppcreative / select-badge example snippets


->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(),

 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; 

public static function select ($select, $options, $types, $icons){
    return [
        Select::make(__('fields.' .$select), $select)
            ->filterable()
            ->displayUsingLabels()
            ->onlyOnForms()
            ->options($options)
            ->rules('}

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),
    ];
}

php artisan vendor:publish --provider="Wame\SelectBadge\SelectBadgeServiceProvider"


    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);
    }


    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',
        ];
    }


    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));
    }
 php
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')  ),
 php
$icon = '';
  ...SelectBadge::select('place_execution', $this->place(), $this->place('type'), place('icon')  ),