Skip to content

Commit 984323a

Browse files
committed
Update StateFusionBulkAction.php
1 parent 803b4f7 commit 984323a

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/Actions/StateFusionBulkAction.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,19 @@ protected function setUp(): void
2828
$this->tooltip(fn () => $this->resolveDescription($this->getFromState()));
2929
$this->setActionAttributes();
3030
$this->action(function (Collection $records, $data) {
31-
if (empty($data)) {
32-
$records->each(fn ($record) => $record->{$this->getAttribute()}?->equals($this->getFromState())
33-
&& in_array(
34-
$this->getToState()::getMorphClass(),
35-
$record->{$this->getAttribute()}->transitionableStates(),
36-
)
37-
? $record->{$this->getAttribute()}->transitionTo($this->getToStateClass())
38-
: null);
39-
} else {
40-
$records->each(fn ($record) => $record->{$this->getAttribute()}?->equals($this->getFromState())
41-
&& in_array(
42-
$this->getToState()::getMorphClass(),
43-
$record->{$this->getAttribute()}->transitionableStates(),
44-
)
45-
? $record->{$this->getAttribute()}->transitionTo($this->getToStateClass(), $data)
46-
: null);
47-
}
31+
$records->each(callback: function ($record) use ($data) {
32+
if ($record->{$this->getAttribute()}->equals($this->getFromState())) {
33+
if (empty($data)) {
34+
if ($record->{$this->getAttribute()}->canTransitionTo($this->getToStateClass())) {
35+
return $record->{$this->getAttribute()}->transitionTo($this->getToStateClass());
36+
}
37+
} else {
38+
if ($record->{$this->getAttribute()}->canTransitionTo($this->getToStateClass(), $data)) {
39+
return $record->{$this->getAttribute()}->transitionTo($this->getToStateClass(), $data);
40+
}
41+
}
42+
}
43+
});
4844
});
4945
}
5046

0 commit comments

Comments
 (0)