Skip to content

Commit

Permalink
Update asset's assigned_to and assigned_type after creating
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmoore committed Jan 9, 2025
1 parent 40b41e6 commit 8597984
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 8597984

Please sign in to comment.