Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions database/factories/CheckoutAcceptanceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,39 @@ public function definition()
'assigned_to_id' => User::factory(),
];
}
protected static bool $skipActionLog = false;

public function withoutActionLog(): static
{
// turn off for this create() call
static::$skipActionLog = true;

// ensure it turns back on AFTER creating
return $this->afterCreating(function () {
static::$skipActionLog = false;
});
}

public function configure(): static
{
return $this->afterCreating(function (CheckoutAcceptance $acceptance) {
if (static::$skipActionLog) {
return; // short-circuit
}
if ($acceptance->checkoutable instanceof Asset) {
$this->createdAssociatedActionLogEntry($acceptance);
}

if ($acceptance->checkoutable instanceof Asset && $acceptance->assignedTo instanceof User) {
$acceptance->checkoutable->update([
'assigned_to' => $acceptance->assigned_to_id,
'assigned_type' => get_class($acceptance->assignedTo),
'assigned_to' => $acceptance->assigned_to_id,
'assigned_type'=> get_class($acceptance->assignedTo),
]);
}
});
}


public function forAccessory()
{
return $this->state([
Expand Down
Loading