beforeSave whith relations

I have the following process in beforeSave() of EditSale.php, in which I restore the stock (quantities) of products, before the records are saved, as indicated by the "beforeSave" hook, but it turns out that when entering this hook the data of the relationship (SaleDetails) has already been saved.

protected function beforeSave(): void
    {
        //antes de guardar, DESHACEMOS EL STOCK
        $originalDetails = $this->record->products->map(function($product) {
            return [
                'product_id' => $product->id,
                'qty' => $product->getOriginal('qty'), // Obtener la cantidad original antes de la modificación
            ];
        });
        dd($originalDetails);
        foreach ($originalDetails as $detail) {
            $product = $detail->product;
            Log::info('revert stock', ['product_id' => $product->id]);
            Log::info('revert stock', ['cant anterior' => $detail->qty]);
            Log::info('revert stock', ['stock anterior' => $product->stock_current]);
            $product->stock_current += $detail->qty;
            $product->save();
        }
        
    }

i.e. where do i get the original detail before it is saved? is there a hook for this? for these cases beforesave does not work.
Was this page helpful?