I have three model : Manager
,Vendor
, Banquet
and the relationship is :
- manager has one vendor
- vendor has many banquet
How to get the all manager with all relation in laravel orm?
$manager = Manager::where('active',1)->get();
$vendor = $manager->vendor()->get();// -- dose not work!
$banquet = $vendor->banquet()->get();// -- dose not work!
Manager model:
class Manager extends Model{
protected $table = 'manager';
protected $primaryKey = 'id';
public function vendor(){
return $this->hasOne('ACME\Entities\Vendor','managerId','id');
}
}
Here is the model
Vendor model:
class Vendor extends Model{
protected $table = 'vendor';
protected $primaryKey = 'id';
public function manager(){
return $this->belongsTo('ACME\Entities\Manager_V','id','managerId');
}
public function banquet(){
return $this->hasMany('ACME\Entities\V_Banquet' ,'vendorId' ,'id');
}
}
Banquet model:
class Banquet extends Model{
protected $table = 'banquet';
protected $primaryKey ='id';
public function vendor()
{
return $this->belongsTo('ACME\Entities\Vendor' ,'vendorId' ,'id');
}
}