System.php 796 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class System extends Model
  5. {
  6. protected $fillable = ['key', 'value'];
  7. public $timestamps = false;
  8. public static function keyValue($key)
  9. {
  10. return optional(System::where('key', $key)->first())->value;
  11. }
  12. public static function optionList()
  13. {
  14. $list = System::all(['key', 'value']);
  15. $system = call_user_func(function () {
  16. $init = [];
  17. $config = array_flip(config('blog.system_key'));
  18. foreach ($config as $key => $value) {
  19. $init[$key] = '';
  20. }
  21. return $init;
  22. });
  23. foreach ($list as $item) {
  24. $system[$item['key']] = $item['value'];
  25. }
  26. return $system;
  27. }
  28. }