Can we take a look at your models?
Feb 25, 2015
3
Level 8
Working with Pivots
OK, I posted something before about my dilemma, but now, I have run into a problem.
I have 3 tables:
vendor (actual vendor)
vendor_client (client specific vendor data)
vendor_vendor_client (pivot - vendor_id - vendor_client_id -- has client_id as a field))
Now, I have the associations done with the model, and I can get the details, etc etc... but now, how can I search though it?
$vendor->where('vendor_vendor_client.client_id', 2)->get()
doesn't get me what I want...
$vendor->details()->where('vendor_vendor_client.client_id', 2)->get();
that gets me a collection, but doesn't get me any items, since the vendor_id is null.
$vendor->find(1)->details()->where('vendor_vendor_client.client_id', 2)->get();
gets me what I want... sorta... because I want to search for a vendor by 'like name'
$vendor->where('name', 'like', 'v%')->details()->where('vendor_vendor_client.client_id', 2)->get();
that just fails...
Is there a way to let the model know that the pivot exists, and to just query that? am I just going about it the wrong way?
HELP!?
Please or to participate in this conversation.