<?php
namespace Modules\System\Models;
use App\Models\MyModel;
class Config extends MyModel
{
protected $table = "my_system_config";
protected $group = 'system';
public function group($name): Config
{
$this->group = $name;
return $this;
}
public function getConfig($key = []): array
{
$whereRaw = $key ? 'cfg_key in (' . join_data($key,',') . ')' : '1=1';
$collect = $this->where('cfg_group', $this->group)->whereRaw($whereRaw)->get();
$result = [];
$collect->map(function ($item, $key) use (&$result) {
$result[$item->cfg_key] = $item->cfg_val;
});
return $result;
}
}