PHP code example of wangzd / laravel-dict

1. Go to this page and download the library: Download wangzd/laravel-dict 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/ */

    

wangzd / laravel-dict example snippets


    Dict::get("global","bool");// 返回:[0=>'否',1=>'是']
    Dict::get("order","status");// 返回:[0=>'待下单',1=>'待支付',2=>'待发货',3=>'已完成']

    Dict::get("global","bool","0");// 返回:否
    Dict::get("order","status","1");// 返回:待支付
    #使用场景
    foreach($orderList as $order) {
        echo '订单是否删除:' . Dict::get("global","bool",$order['is_del']);//否
        echo '订单状态:' . Dict::get("order","status",$order['status']);//待支付
    }

    Dict::value("order","status","wait_pay"); //等待支付状态 返回:1
    if($orderStatus == Dict::value("order","status","wait_pay") {
        //如果订单状态是待支付    
    }
    
    Dict::valueName("order","status","wait_pay"); 返回 待支付

    //建议直接在数据库维护base_dictionary_option表
	#添加
    Dict::add($table_code,$code,$key,$value,$name,$sort=0,$input='');//obj
    Dict::add('global','bool','yes','0','否');//obj
    #修改
    Dict::edit('global','bool',['yes','0','否]);//bool
    #删除
    Dict::delete('global','bool');/bool 

    //如果在数据库添加,需要单独条用该方法
    Dict::updateCache();

Wangzd\Dict\DictServiceProvider::class,

'Dict' => Wangzd\Dict\Facades\Dict::class