Skip to content

Commit

Permalink
修正destory方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Feb 12, 2023
1 parent 653adaf commit 299e896
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,13 @@ public static function destroy($data, bool $force = false): bool

if (is_array($data) && key($data) !== 0) {
$query->where($data);
$data = null;
$data = [];
} elseif ($data instanceof \Closure) {
$data($query);
$data = null;
$data = [];
}

$resultSet = $query->select($data);
$resultSet = $query->select((array) $data);

foreach ($resultSet as $result) {
$result->force($force)->delete();
Expand Down
2 changes: 1 addition & 1 deletion src/db/concern/ResultOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function throwNotFound(): void
*
* @return array|Collection|static[]
*/
public function selectOrFail($data = null)
public function selectOrFail($data = [])
{
return $this->failException(true)->select($data);
}
Expand Down
6 changes: 3 additions & 3 deletions src/model/concern/SoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ public static function destroy($data, bool $force = false): bool

if (is_array($data) && key($data) !== 0) {
$query->where($data);
$data = null;
$data = [];
} elseif ($data instanceof \Closure) {
call_user_func_array($data, [&$query]);
$data = null;
$data = [];
} elseif (is_null($data)) {
return false;
}

$resultSet = $query->select($data);
$resultSet = $query->select((array) $data);

foreach ($resultSet as $result) {
/** @var Model $result */
Expand Down
2 changes: 1 addition & 1 deletion src/model/relation/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function eagerlyResultSet(array &$resultSet, string $relation, array $sub
// 多态类型映射
$model = $this->parseModel($key);
$obj = new $model();
if (!\is_null($closure)) {
if (!is_null($closure)) {
$obj = $closure($obj);
}
$pk = $obj->getPk();
Expand Down

0 comments on commit 299e896

Please sign in to comment.