I have two tables
, users
and products. Products table structure is:
id | product_name | user_id | isGlobal |
---|---|---|---|
1 | apple | 10 | 0 |
2 | banana | 10 | 1 |
3 | pear | 20 | 0 |
4 | melon | 30 | 0 |
Here is User model where made relation with products
public function product()
{
return $this->hasMany(Product::class);
}
Controller which i'm getting products
$products = $user->product()->get();
Problem: Product with isGlobal = 1
param must be shown for every user.
How can solve this?
PS: below solution did not work.
public function product()
{
return $this->hasMany(Product::class)->where('isGlobal', 1);
}