Ad
How Can I Make Query For Relationship?
I have a product table and a color table. And I have the following relation for them:
public function colors() {
return $this->belongsToMany('App\Color','product_colors');
}
I want to find out what product have more than 3 colors. How can I do this?
Ad
Answer
You can try simply with this :
$products = Product::has('colors', '>', 3)->get()
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad