v0.1.10
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace kernel\modules\option\service;
|
||||
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\option\models\Option;
|
||||
|
||||
class OptionService
|
||||
@@ -49,6 +50,26 @@ class OptionService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function createOrUpdate(string $key, string $value, string $label = ''): false|Option
|
||||
{
|
||||
/** @var Option $option */
|
||||
$option = self::getItemObject($key);
|
||||
if (!$option) {
|
||||
$option = new Option();
|
||||
$option->key = $key;
|
||||
}
|
||||
$option->value = $value;
|
||||
if (!empty($label)){
|
||||
$option->label = $label;
|
||||
}
|
||||
|
||||
if ($option->save()) {
|
||||
return $option;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return false|array|string
|
||||
@@ -63,6 +84,20 @@ class OptionService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return false|array|string|Option
|
||||
*/
|
||||
public static function getItemObject($key): false|array|string|Option
|
||||
{
|
||||
$item = Option::where("key", $key)->first();
|
||||
if ($item){
|
||||
return $item;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function removeOptionByKey(string $key): bool
|
||||
{
|
||||
$option = Option::where("key", $key)->first();
|
||||
|
Reference in New Issue
Block a user