Thanks for the replies.
I have sort of managed to get this to work via a method which seems totally backwards and dirty. The only problem with it is that this creates 1 query per field retrieved. I eventualy need to pull more fields using the role so I figure this will end up creating tons of extra queries:
Normal query
select * from [Connection] where [Connection].[Record1Id] in ('15AGA3494-7AE5-E711-834E6-343453456B82B3F', '23334424D-FABE-E711-834E4-343453456B82B3F', '679D6E15-F247-E511-AEE6-343453456924777', '68A4558F-E91A-E811-834E9-343453456B82B3F', '68C747C1-92EF-E511-834D2-343453456B82DD8', '6D3A1EE9-59FF-E611-834E2-343453456B82DD8', 'A762675D-233434-E711-834DC-343453456B82B3F', 'AE814366-7FE7-E111-8AFD-343453456924777', 'C18A83F9-2363-E811-834F2-343453456B82DD8', 'CA41A39A-2663-E811-834F2-343453456B82DD8') and [record2objecttypecode] = '8' and [record1objecttypecode] = '3' and [connection].[statuscode] = '1'
Repeated query example
select * from [Connection] where [Record2RoleIdName] = 'Bid Manager' and [Record1Id] = '23334424D-FABE-E711-834E4-343453456B82B3F' and [record2objecttypecode] = '8' and [record1objecttypecode] = '3' and [connection].[statuscode] = '1'
The query is basically the same so i'm sure these can be ingratiated somehow.
BidController:
$bids = Bid::where('mandatory', 1)->with('crm')->paginate(10);
foreach($bids as $b)
{
$team[$b->crm_ref]['Bid_Manager'] = TeamMember::role('Bid Manager', $b->crm->OpportunityId);
}
return view('public.bids.mandatory.index', compact('bids', 'team'));
I can then access this in the view via
$team[$bid->crm_ref]['Bid_Manager'].
I am using the following scope in the TeamMember model:
public function scopeRole($query, $type, $opportunity)
{
return $query->where('Record2RoleIdName', $type)->where('Record1Id', $opportunity)->get();
}
is there a better way of doing this?