Skip to content

Commit

Permalink
Merge pull request #16051 from marcusmoore/testing/checkoutable-accep…
Browse files Browse the repository at this point in the history
…tance-factory-fix

Update related asset when checkout acceptance created via factory
  • Loading branch information
snipe authored Jan 10, 2025
2 parents ec85e4b + 8597984 commit f0bcf78
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions database/factories/CheckoutAcceptanceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Accessory;
use App\Models\Asset;
use App\Models\CheckoutAcceptance;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand All @@ -23,6 +24,18 @@ public function definition()
];
}

public function configure(): static
{
return $this->afterCreating(function (CheckoutAcceptance $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),
]);
}
});
}

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

0 comments on commit f0bcf78

Please sign in to comment.