php - Collection result manipulation with Laravel
I am writing a follower module to my site and I got some problems with it. I want to list all the useres but only those ones that are not followed by me. I use this function to get them:
**
* Listing users
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @todo Valamiért hat kétjegyű az követendő user id akkor a scope lehal
*/
public function listUsers() {
//Declare an empty array for the result of the 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 with the ids from 0 - 9 when I use without explode but with ids from 10 - ... it kills my Pending scope. The goal would be that add some char into the end of the id (in our case it is ,) and explode it. I did that but it kills my scope from the very begining.
What do you think, what could be possibly wrong? Am I using it absolutely wrong?
Thank you for your answers!
Answer
Solution:
Okay, I simply use a foreach before my scope, put every element into an array and it works like a charm!