Asset::class, 'checkoutable_id' => Asset::factory(), 'assigned_to_id' => User::factory(), ]; } public function configure(): static { return $this->afterCreating(function (CheckoutAcceptance $acceptance) { // @todo: add comment if ($acceptance->checkoutable instanceof Asset) { $acceptance->checkoutable->assetlog()->create([ 'action_type' => 'checkout', 'target_id' => $acceptance->assigned_to_id, 'target_type' => get_class($acceptance->assignedTo), 'item_id' => $acceptance->checkoutable_id, 'item_type' => $acceptance->checkoutable_type, ]); } 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([ 'checkoutable_type' => Accessory::class, 'checkoutable_id' => Accessory::factory(), ]); } public function pending() { return $this->state([ 'accepted_at' => null, 'declined_at' => null, ]); } public function accepted() { return $this->state([ 'accepted_at' => now()->subDay(), 'declined_at' => null, ]); } }