I have a variable that is a pagination object
$pagination
I am changing things inside of it using transform
$pagination->getCollection()->transform(function ($item, $key) use(&$data, &$pagination) {
$item->foo = 'bar';
}
I want to remove an item from the pagination if it meets a certain condition. I don't want it removed until after I've been able to use the data. Following is an example.
$pagination->getCollection()->transform(function ($item, $key) use(&$data, &$pagination) {
$data[] = $item->foo;
if ($item->foo === 'bar') {
$item->remove();
}
}
I've also tried using $pagination->getCollection()->forget($key);
inside of the transform
$pagination->getCollection()->transform(function ($item, $key) use(&$data, &$pagination) {
$data[] = $item->foo;
if ($item->foo === 'bar') {
$pagination->getCollection()->forget($key);
}
}
That's from this question.
How to unset (remove) a collection element after fetching it?
I'm guessing the fact I'm dealing with a pagination may be making these answers not apply to my situation.