Configuration.php 652 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Configuration extends Model
  6. {
  7. use HasFactory;
  8. public $primaryKey = 'key';
  9. public $incrementing = false;
  10. protected $keyType = 'string';
  11. protected $fillable = [
  12. 'key',
  13. 'value',
  14. 'type',
  15. ];
  16. /**
  17. * @param string $key
  18. * @param $default
  19. * @return mixed
  20. */
  21. public static function getValueByKey(string $key , $default = null)
  22. {
  23. $configuration = self::find($key);
  24. return $configuration ? $configuration->value : $default;
  25. }
  26. }