for example: user favorites
Fields of the three tables:
User: id
Product: id, current_price
product_user: id, user_id, product_id, expected_price
App\User
public function products(){
return $this->belongsToMany("App\Product")->withPivot("expected_price")
}
how to find items that are currently collected by login users and whose current prices are lower than expected?
at present, what I can think of is to find out all the items in the user"s collection first, and then compare it with the corresponding expected_price with foreach one by one. Is there a more elegant way that laravel comes with?