many updates 😁

This commit is contained in:
Paul Spenke
2023-07-02 21:30:29 +08:00
parent 788a6b323c
commit a529852fd8
29 changed files with 353 additions and 204 deletions
@@ -90,7 +90,12 @@ class BaseRepository
}
$values = array_values($data);
$values[] = $instance->id ?? $instance->getId();
if(is_array($instance) && $instance['id']) {
$values[] = $instance['id'];
} else {
$values[] = $instance->id ?? $instance->getId();
}
return $this->db->query(
"UPDATE {$this->table} SET {$set} WHERE id=?",
@@ -21,19 +21,27 @@ class SettingRepository extends BaseRepository implements SettingRepositoryContr
*/
public function updateSettings(array $data)
{
$this->destroyAll();
foreach ($data as $key => $value) {
$isArray = is_array($value) ? 1 : 0;
if ($isArray) {
$value = implode(',', $value);
}
$this->create([
'setting' => $key,
'value' => $value,
'is_array' => $isArray,
]);
$ins = $this->findWhere('setting', $key);
if (empty($ins)) {
$this->create([
'setting' => $key,
'value' => $value,
'is_array' => $isArray,
]);
} else {
$this->update($ins[0], [
'setting' => $key,
'value' => $value,
'is_array' => $isArray,
]);
}
}
return true;