| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Modes;
- use Illuminate\Database\Eloquent\Model;
- /**
- * App\Modes\Config
- *
- * @property int $id
- * @property string $key 配置值
- * @property string $content 配置内容
- * @property int $type 数据类型 1-string 2-json
- * @property string $remark 备注
- * @property \Illuminate\Support\Carbon $created_at
- * @property \Illuminate\Support\Carbon $updated_at
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config query()
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereContent($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereCreatedAt($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereId($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereKey($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereRemark($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereType($value)
- * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereUpdatedAt($value)
- * @mixin \Eloquent
- */
- class Config extends Model
- {
- protected $table = 'config';
- /**
- * 获取配置内容
- * @author fatty
- * @date 2018/12/24
- * @param $rule
- * @return array
- * @description
- */
- public static function getConfigByKey($rule, $accessArray)
- {
- if (in_array($rule, $accessArray)) {
- $result = Config::getValue($rule);
- }
- return isset($result) ? $result : [];
- }
- /**
- * 获取配置内容
- * @author fatty
- * @date 2018/12/17
- * @param $key
- * @return bool|mixed
- * @description
- */
- public static function getValue($key)
- {
- $key = strtoupper($key);
- $config = Config::where('key', $key)->first();
- if ($config) {
- if ($config->type == 2) {
- $data = json_decode($config->content, true);
- } else {
- $data = $config->content;
- }
- return $data;
- }
- return false;
- }
- }
|