php - Collection result manipulation with Laravel -


i writing follower module site , got problems it. want list useres ones not followed me. use function them:

**      * listing users      * @return \illuminate\contracts\view\factory|\illuminate\view\view      * @todo valamiért hat kétjegyű az követendő user id akkor scope lehal      */     public function listusers() {          //declare empty array result of collection         $ids = array();          $collection = $this->user->followers;         $collection->each(function($follower) use (&$ids) {             $ids[] = explode(',', $follower->id . ',');         });           $users = user::pending($ids)->get();          dd($users);          return view('profile.listusers', [             'users' => $users,             '_user' => $this->user,         ]);     } 

it works fine ids 0 - 9 when use without explode ids 10 - ... kills pending scope. goal add char end of id (in our case ,) , explode it. did kills scope begining.

what think, possibly wrong? using absolutely wrong?

thank answers!

okay, use foreach before scope, put every element array , works charm!

foreach($collection $follower) {             $ids[] = $follower->id;         } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -