use pivot table and also make relationships with customer with services and vendors and when u can call nested eager load
Mar 24, 2017
1
Level 1
3 models and 2 pivot tables
I have 3 models :
class Customer extends Model
{
// here is my question
}
class Vendor extends Model
{
/**
* The services of vendor.
*/
public function services()
{
return $this->belongsToMany('App\Service');
}
}
class Service extends Model
{
/**
* The services of vendor.
*/
public function vendors()
{
return $this->belongsToMany('App\Vendor');
}
}
so each vendor can have one or few services. also each service can belongs to one or more vendors ( Vendor - many to many - Service )
a customer can have one or more vendor services. so the Cusomer model has many to many relationship with the pivot table of Vendor-Service ( another pivot table between Customer and VendorService which is pivot table itself)
I want to have another pivot table (customer_vendorservices) which contains of customer_id and vendorservice_id what should I do ? using Pivot Model and call it VendorService? any other solutions ?
Please or to participate in this conversation.