database - Filtering queryset with objects -
currently have
foreach($this->friends $friend) { $user_ids[] = $friend->id; } $posts = post::wherein("user_id", $user_ids)->orderby("date_published", "desc")->paginate(15);
seems okay , works fine, creation of array little weird. there way filter user objects themselves? example
post::wherein("user", $this->friends)
where $this->friends
public function friends() { return $this->belongstomany("app\user", "friends_users", "user_id", "friend_id"); }
$this->friends
collection
object has lists
method creates array column, or associative array 2 columns. here's how use it.
$posts = post::wherein("user_id", $this->friends->lists('id'))->orderby("date_published", "desc")->paginate(15);
Comments
Post a Comment