Update asset's assigned_to and assigned_type after creating
This commit is contained in:
parent
40b41e646d
commit
8597984787
1 changed files with 13 additions and 0 deletions
|
@ -4,6 +4,7 @@ namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\CheckoutAcceptance;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
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()
|
public function forAccessory()
|
||||||
{
|
{
|
||||||
return $this->state([
|
return $this->state([
|
||||||
|
|
Loading…
Add table
Reference in a new issue