Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 2 years ago.
0

I think the problem here is,

In your collections the items property is empty, which is an array inside the collection. The reverse function uses this items property.

so if you want to use all the collection class's functions, set the items array instead of $some_array.

   public function setArray(){
        $this->items = [1,2,3];
    }

or override the reverse function like this

public function reverse()
{
    return new static(array_reverse($this->some_array));
}

the first solution is better.

Last updated 8 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.

© 2024 Laravel.io - All rights reserved.