I can't quite wrap my head around this.
I have a product, that a user can make an offer on.
A user can make an offer on many products, and a product can have many offers at any given moment(think eBay but multiple people sending separate offers)
Do I need a many to many relationship for an offers migration for example, that references both the product and the user with associated fields in the database?
To me it should be
User->hasMany('App\Offers')
Product->hasMany('App\Offers')
On offers
Offer->belongsTo('App\Users')
Offer->belongsTo('App\Product')
Obviously this doesn't use many to many but because I have three models im interacting with, how is it best to model this?
you should create product_offers pivot table .
Offer model :
class Offer extends Model
{
public function products(){
$this->belongsToMany('App\Product', product_offers);
}
public function users(){
$this->belongsTo('App\User');
}
Product Model:
class Product extends Model
{
public function offers(){
$this->belongsToMany('App\Offer', product_offers);
}
}
User Model:
class User extends Model
{
public function offers(){
$this->hasMany('App\Offer');
}
}