I would like to ask about the User
, Cart
and Product
eloquent relationships. The User
hasOne Cart
and the Cart
can have many Product
.
class User {
public function cart()
{
return $this->hasOne(App\Cart::class);
}
}
class Cart {
public function user()
{
return $this->belongsTo(App\User::class);
}
public function products()
{
return $this->hasMany(App\Product::class);
}
}
class Product {
//
}
I have database table structured like:
users
- id
- email
- username
- password
carts
- id
- user_id
- product_id
- quantity
products
- id
- name
- price
Is this correct?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire