Assuming you setup the relationships in the Eloquent, try this:
I don't actually know if that would work for sure, but give it a try.
$companies = Company::whereNotNull('businessclub_id')->whereHas('activities', function($query) {
// $query->wherePivot('countrycode', 'ml'); // Apparently this doesn't work
$query->where('countrycode', 'ml'); // But this does
})->get();
Thanks for answering back.
It is not working, here is the error im getting
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pivot' in 'where clause' (SQL: select * from companies where businessclub_id is not null and exists (select * from activities inner join activity_company on activities.id = activity_company.activity_id where companies.id = activity_company.company_id and pivot = countrycode))
I am getting this Error: "Property [name] does not exist on this collection instance. (View: C:\Users\KEITA\ibafrica\resources\views\homes\index.blade.php)"
and it is related to this {{$BMS->activity->name}}