ModelAppendFieldTrait.php 1.4 KB
<?php
/**
 * +--------------------------------------------------------------------------------------------------------------------
 * trait :model 需要添加字段 trait
 * +--------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\Traits
 * @package   App\Models\Traits
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年7月19日15:55:15
 * @copyright 2020-2022 Richer (http://www.xxxxxx.com)
 * @license   http://www.xxxxxx.com License
 * @link      http://www.xxxxxx.com
 */
namespace App\Models\Traits;

use Illuminate\Support\Arr;

/**
 * Trait ModelAppendFieldTrait
 *
 * @category  App\Models\Traits
 * @package   App\Models\Traits
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年7月19日15:55:15
 * @copyright 2020-2022 Richer (http://www.xxxxxx.com)
 * @license   http://www.xxxxxx.com License
 * @link      http://www.xxxxxx.com
 */
trait ModelAppendFieldTrait
{
    /**
     * 访问器被附加到模型数组的形式。
     *
     * @var array
     */
//    protected $appends = ['status_show'];

    /**
     * 获取状态的中文显示
     *
     * @return mixed
     */
    public function getStatusShowAttribute()
    {
        return __(Arr::get(config('constants.STATUS_OPTIONS'), $this->status ? : config('constants.STATUS_OK')));
    }
}