This commit is contained in:
2023-07-31 23:26:58 +08:00
parent 00a2125efc
commit e575254139
+7 -5
View File
@@ -320,17 +320,19 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
/** /**
* @param null $condition * @param array|string|null $condition
* @param array $attributes * @param array $attributes
* *
* @return bool * @return bool
* @throws Exception * @throws Exception
*/ */
protected static function deleteByCondition($condition = NULL, array $attributes = []): bool protected static function deleteByCondition(array|string|null $condition = NULL, array $attributes = []): bool
{ {
$model = static::query(); $model = static::query()->bindParams($attributes);
if (!empty($condition)) { if (is_array($condition)) {
$model->where($condition)->bindParams($attributes); $model->where($condition);
} else if (is_string($condition)) {
$model->whereRaw($condition);
} }
return (bool)$model->delete(); return (bool)$model->delete();
} }