class Company extends Model
{
public function company_settings()
{
return $this->belongsToMany('CompanySetting');
}
}
class SettingsGroup extends Model
{
public $table = 'settings_groups';
public function comapanySettings() {
return $this->hasMany('CompanySetting');
}
}
class CompanySetting extends Model
{
public function groups () {
return $this->belongsToMany('SettingsGroups');
}
public function company_settings()
{
return $this->belongsToMany('Company');
}
}
I want to get the companys settings: Company::whereHas('company_settings', function ($q) use ($company) { $q->where('company_id',$company->id);})->get();
But it returns the company, not the settings. What am i doing wrong? Thanks!!
Edited with all the Models, $companies = Company::with('company_settings')->get(); also returns all the companies
Thanks!
Many To Many
relationship, show use more code please. at least the both Models. – Zakaria Acharki