Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgrim's avatar

Returning a model after update still shows old values

Hi, When I update a record and then try to return the values right away I am seeing that it is the old record.

public function update(Request $request, Price $price)
    {
        $material = $price->material->prices->filter(function ($value) use ($price) {
            return $value->id >= $price->id;
        });
        $prices = $material->pluck('id');
        Price::whereIn('id', $prices)->update([
            'price' => $request->price
        ]);
        return $price->material->prices;
    }

it returns my old prices. However when I then reload the page it has the latest prices. Do I need to tell laravel to wait until the record is updated before doing?

return $price->material->prices;
0 likes
3 replies
jlrdw's avatar

It uses the first return:

return $value->id >= $price->id;

Please or to participate in this conversation.