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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -