mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Update asset's assigned_to and assigned_type after creating
This commit is contained in:
parent
40b41e646d
commit
8597984787
|
@ -4,6 +4,7 @@ namespace Database\Factories;
|
|||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
|
@ -23,6 +24,18 @@ class CheckoutAcceptanceFactory extends Factory
|
|||
];
|
||||
}
|
||||
|
||||
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([
|
||||
|
|
Loading…
Reference in a new issue