Skip to content

Commit be4362c

Browse files
authored
Merge pull request #17925 from Godmartinz/fix-factory-auto-gen-action-logs
Adds option to disable auto generating action log from acceptance factory
2 parents 7d07420 + 82bdd43 commit be4362c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

database/factories/CheckoutAcceptanceFactory.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,39 @@ public function definition()
2323
'assigned_to_id' => User::factory(),
2424
];
2525
}
26+
protected static bool $skipActionLog = false;
27+
28+
public function withoutActionLog(): static
29+
{
30+
// turn off for this create() call
31+
static::$skipActionLog = true;
32+
33+
// ensure it turns back on AFTER creating
34+
return $this->afterCreating(function () {
35+
static::$skipActionLog = false;
36+
});
37+
}
2638

2739
public function configure(): static
2840
{
2941
return $this->afterCreating(function (CheckoutAcceptance $acceptance) {
42+
if (static::$skipActionLog) {
43+
return; // short-circuit
44+
}
3045
if ($acceptance->checkoutable instanceof Asset) {
3146
$this->createdAssociatedActionLogEntry($acceptance);
3247
}
3348

3449
if ($acceptance->checkoutable instanceof Asset && $acceptance->assignedTo instanceof User) {
3550
$acceptance->checkoutable->update([
36-
'assigned_to' => $acceptance->assigned_to_id,
37-
'assigned_type' => get_class($acceptance->assignedTo),
51+
'assigned_to' => $acceptance->assigned_to_id,
52+
'assigned_type'=> get_class($acceptance->assignedTo),
3853
]);
3954
}
4055
});
4156
}
4257

58+
4359
public function forAccessory()
4460
{
4561
return $this->state([

0 commit comments

Comments
 (0)