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
Post a Comment