1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Models\Model;
- class Setting extends Model
- {
- /**
- * @var string
- */
- protected $table = 'base_settings';
- protected $guarded = [];
- protected $casts = [
- 'value' => 'json',
- 'limit' => 'json',
- ];
- public static function checkCodeIsUnique($code, $ignore_id = 0)
- {
- return self::query()->where('code', $code)->where('id', '<>', $ignore_id)->exists();
- }
- /**
- * 根据code获取值
- * @param $code
- * @return string|mixed
- */
- public static function byCodeGetSetting($code)
- {
- // return Cache::tags('model')->remember('model:Setting:byCodeGetSetting:' . $code, Carbon::now()->addDays(1), function () use ($code) {
- $val = self::query()->where('code', $code)->value('value');
- return $val;
- // });
- }
- /**
- * 根据codes获取值
- * @param array $codes
- * @return array|mixed
- */
- public static function byCodesGetSettings(array $codes)
- {
- // return Cache::tags('model')->remember('model:Setting:byCodesGetSettings:' . arr2str($codes), Carbon::now()->addDays(1), function () use ($codes) {
- return self::query()->whereIn('code', $codes)->pluck('value', 'code')->toArray();
- // });
- }
- }
|