id
product_name
user_id
isGlobal
1
Apfel
10
0
2
Banane
10
1
3
Birne
20
0
4
Melone
30
0
Hier ist das Benutzermodell, in dem eine Beziehung zu Produkten hergestellt wurde
Code: Select all
public function product()
{
return $this->hasMany(Product::class);
}
Code: Select all
$products = $user->product()->get();
Wie kann das gelöst werden?
PS: Die folgende Lösung hat nicht funktioniert.
Code: Select all
public function product()
{
return $this->hasMany(Product::class)->where('isGlobal', 1);
}
Mobile version