I am trying to run a method for each item within a collection. This is an object method located in the same class:
protected function doSomething() { $discoveries = $this->findSomething(); $discoveries->each([$this, 'doSomethingElse']); } protected function doSomethingElse($element) { $element->bar();
If I precede a call to Collection::each with the is_callable([$this, 'doSomethingElse']) tag is_callable([$this, 'doSomethingElse']) , it returns true, so apparently it could be called. However, the call itself throws an exception:
Type error: argument 1 passed to the illustration \ Support \ Collection :: each () must be called, the array is specified, called in ---. php on line 46
The method to call can be found here .
I will get around this by simply passing a closure that itself simply calls this function, but it is certainly a much cleaner solution, and I cannot understand why it throws an error.
collections php laravel
Padarom
source share