Hello! :)
I want to return all the statuses of a user and his friends, sort of like a news feed, sorted by earliest posted first. I used to do this in Laravel by creating a array filled with user ids, and then doing a query that returns all statuses where user _ id is one of the ID's from the array.
I can't get the ids properly into a array, and even if I got that to work I have no idea how to do a query where you return all where user_id is equal to one of the ids in the array.
This is how I did it in Laravel:
public function getFeedForUser(User $user) {
// Get friends user ID's
$userIds = $user->followedUsers()->lists('followed_id');
// Add Users own ID to array
$userIds[] = $user->id;
//Return all statuses that contains the given ID's
return Status::whereIn('user_id', $userIds)->latest()->get();
}
First I need a array of all the ID's of the users friends. I use a pivot table through a friends.php model to check friendships. Basically I need a query that returns all the friends id in a array.
I'm currently doing somehting like this in Users.php:
$friendsIDs = $this->getFollowing([
"columns" => "followed_id"
])->toArray();
var_dump($friendsIDs);
which gives:
array(3) {
[0]=> array(1) { ["followed_id"]=> string(1) "4" }
[1]=> array(1) { ["followed_id"]=> string(1) "6" }
[2]=> string(1) "1" }
Where 4 and 6 are the ID's of the users this user is following. 1 is the ID of the user. As you can see only the users own id is properly inserted as array, not the other two. Don't know how to format it so that I only get the id and not the rest.
Say this works, I then want to use this array as a condition. Basically statuses.php has a user _ id collumn, and I want to return all statuses in order that has one of the ids from that array.
Thank you!!