Support the ongoing development of Laravel.io →
Architecture

I'm having a bit of trouble with a presenter i'm writing. In essence, I want to run a function to organise a bunch of data once, then let other functions utilise that organised data without altering it.

I've mocked up a simple example: http://laravel.io/bin/REkO8

If I run $payslip->present()->paymentsAbove(10) it alters each contract->transactions entity within $itemsByContract, so if I were to run $payslip->present()->paymentsBelow(10) it wouldn't return any items because the first function already filtered them out.

Is there anything I can do short of running something like this each time I want to use one of the functions?

private function cloneStuff()
{
	$_items = $this->itemsByContract;

	$items = new Collection;

	foreach ($_items as $_item) {
		$item = clone $_item;
		$items->push($item);
	}

	return $items;
}
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.